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 <iostream>
#include <algorithm>
using namespace std;
#define MAXK 100000
int n, k, d, p[MAXK + 1];
struct BLOCK {
int cost, value;
} b[MAXK + 5]; int bn;
inline bool cmp(BLOCK b1, BLOCK b2) {
if (b1.value != b2.value) return b1.value > b2.value;
return b1.cost < b2.cost;
}
int res;
void solve(int sum, int D) {
for (int i = 1; i <= bn; i++) {
if (b[i].cost <= D) {
D -= b[i].cost;
sum += b[i].value;
}
}
if (res < sum) res = sum;
}
int main() {
cin >> n >> k >> d;
for (int i = 1; i <= k; i++) cin >> p[i];
for (int i = 2; i <= k; i++) b[++bn] = { 2, p[i] - p[i - 1] - 1 };
sort(b + 1, b + bn + 1, cmp);
solve(0, d);
solve(p[1] - 1, d - 1);
solve(n - p[k], d - 1);
solve(p[1] - 1 + n - p[k], d - 2);
cout << res;
}
# | 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... |