Submission #20131

#TimeUsernameProblemLanguageResultExecution timeMemory
20131hongjun7격자 보존하기 (GA9_preserve)C++14
61 / 100
167 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; } inline bool cmp2(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 = 0, D = 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]; bn = 0; b[++bn] = { 1, p[1] - 1 }; b[++bn] = { 1, n - p[k] }; for (int i = 2; i <= k; i++) b[++bn] = { 2, p[i] - p[i - 1] - 1 }; sort(b + 1, b + bn + 1, cmp); solve(); bn = 0; b[++bn] = { 1, p[1] - 1 }; for (int i = 2; i <= k; i++) b[++bn] = { 2, p[i] - p[i - 1] - 1 }; sort(b + 1, b + bn + 1, cmp); solve(); bn = 0; b[++bn] = { 1, n - p[k] }; for (int i = 2; i <= k; i++) b[++bn] = { 2, p[i] - p[i - 1] - 1 }; sort(b + 1, b + bn + 1, cmp); solve(); bn = 0; for (int i = 2; i <= k; i++) b[++bn] = { 2, p[i] - p[i - 1] - 1 }; sort(b + 1, b + bn + 1, cmp); solve(); bn = 0; b[++bn] = { 1, p[1] - 1 }; b[++bn] = { 1, n - p[k] }; for (int i = 2; i <= k; i++) b[++bn] = { 2, p[i] - p[i - 1] - 1 }; sort(b + 1, b + bn + 1, cmp2); solve(); bn = 0; b[++bn] = { 1, p[1] - 1 }; for (int i = 2; i <= k; i++) b[++bn] = { 2, p[i] - p[i - 1] - 1 }; sort(b + 1, b + bn + 1, cmp2); solve(); bn = 0; b[++bn] = { 1, n - p[k] }; for (int i = 2; i <= k; i++) b[++bn] = { 2, p[i] - p[i - 1] - 1 }; sort(b + 1, b + bn + 1, cmp2); solve(); bn = 0; for (int i = 2; i <= k; i++) b[++bn] = { 2, p[i] - p[i - 1] - 1 }; sort(b + 1, b + bn + 1, cmp2); solve(); 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...