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 <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <set>
using namespace std;
int first(vector<int>& dist, int num) {
num = min((int)dist.size(), num);
int res = 0;
for (int i=0; i<num; i++) res += dist[i];
return res;
}
int main()
{
int n, k, d;
cin >> n >> k >> d;
vector<int> horse(k);
for (int i=0; i<k; i++) cin >> horse[i];
sort(horse.begin(), horse.end());
int ll = horse[0] - 1;
int rr = n - horse[k-1];
vector<int> dist;
for (int i=0; i<k; i++) dist.push_back(horse[i+1]-horse[i]-1);
sort(dist.rbegin(), dist.rend());
int res = 0;
res = max(res, first(dist, d/2));
res = max(res, max(ll, rr) + first(dist, (d-1)/2));
if (d >= 2) res = max(res, ll + rr + first(dist, d/2-1));
cout << res << endl;
}
# | 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... |