Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define fi first
- #define se second
- #define fin(s) freopen( s, "r", stdin );
- #define fout(s) freopen( s, "w", stdout );
- const long long N = 200100;
- const long long Q = 10010;
- const long long mod = 1000000007;
- const long long block = 500;
- using namespace std;
- int n, k, m;
- int a[N];
- int d[N];
- void solve()
- {
- cin >> n >> k >> m;
- for(int i = 1; i <= m; i++){
- cin >> a[i];
- }
- sort(a + 1, a + m + 1);
- int ans = 0;
- for(int i = 1; i <= m; i++){
- int l = 0, r = i - 1;
- while(l < r){
- int m = (l + r) / 2 + 1;
- if(a[i] - k + 1 <= a[m]){
- r = m - 1;
- }
- else{
- l = m;
- }
- }
- if(l == 0){
- d[i] = max(0, a[i] - k);
- }
- else{
- d[i] = d[l] + (a[i] - k + 1) - a[l] - 1;
- }
- if(a[i] + k - 1 >= a[m]){
- ans = max(ans, d[i - 1] + max(0, n - (a[i] + k - 1)) + a[i] - a[i - 1] - 1);
- }
- }
- ans = max(ans, d[m] + n - a[m]);
- cout << ans << "\n";
- }
- bool mtest = false; int main()
- {
- //fin("input.txt");
- //fout("output.txt");
- //fin("mine.in");
- //fout("mine.out");
- ios_base::sync_with_stdio(0);
- int TE = 1;
- if(mtest)
- cin >> TE;
- while(TE--)
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement