Submission #20132

#TimeUsernameProblemLanguageResultExecution timeMemory
20132hongjun7격자 보존하기 (GA9_preserve)C++14
100 / 100
71 ms2892 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...