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 <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
vector<pair<int, int> > h;
int n,k,d;
int main()
{
scanf ("%d %d %d",&n,&k,&d);
int s = -1, e = -1;
for (int i=0,p;i<k;i++){
scanf ("%d",&p);
if (e + 1 != p){
if (e != -1) h.push_back(make_pair(s,e));
s = e = p;
}
else e++;
}
h.push_back(make_pair(s,e));
int u[3] = {0,max(h.front().first-1,n-h.back().second),h.front().first-1+n-h.back().second};
vector<int> gap;
for (int i=1;i<h.size();i++) gap.push_back(h[i].first - h[i-1].second - 1);
gap.push_back(0);
int sum = 0, bar = gap.size() * 2;
for (int g : gap) sum += g;
sort(gap.begin(),gap.end());
int ans = 0;
for (int g : gap){
sum -= g; bar -= 2;
for (int i=0;i<3;i++) if (bar + i <= d){
if (ans < sum + u[i])
ans = sum + u[i];
}
}
printf ("%d\n",ans);
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... |