This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int MAX = 100020;
int n, d, k, data[MAX];
void input(){
scanf("%d%d%d", &n, &k, &d);
for(int i = 0; i < k; i++)
scanf("%d", &data[i]);
}
vector < int > gap;
int res;
void solve(){
int front = data[0]-1, rear = n-data[k-1];
for(int i = 1; i < k; i++)
gap.push_back(data[i]-data[i-1]-1);
sort(gap.begin(), gap.end());
if(d >= 1){
res = max(res, front);
res = max(res, rear);
}
if(d >= 2)
res = max(res, front+rear);
int index = k-2, current = 0;
while(index >= 0 && d >= 2){
d -= 2;
current += gap[index--];
res = max(res, current);
if(d >= 1){
res = max(res, current+front);
res = max(res, current+rear);
}
if(d >= 2)
res = max(res, current+front+rear);
}
printf("%d\n", res);
}
int main(){
input();
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |