Submission #12156

#TimeUsernameProblemLanguageResultExecution timeMemory
12156xhae격자 보존하기 (GA9_preserve)C++14
100 / 100
28 ms1868 KiB
#include <cstdio> #include <algorithm> using namespace std; int n, K, data[100000], cand[99999], d; int main(void) { scanf("%d %d %d", &n, &K, &d); int start, end; for(int i = 0; i < K; i++) { scanf("%d", data + i); if(i == 0) start = data[0] - 1; if(i == K - 1) end = n - data[i]; if(i > 0) cand[i - 1] = data[i] - data[i - 1] - 1; } sort(cand, cand + K - 1); int ans = 0; int cur = 0; for(int i = 0; i < K - 1; i++) { if((i + 1) * 2 > d) break; int ind = K - 2 - i; cur += cand[ind]; } ans = cur; cur = max(start, end); for(int i = 0; i < K - 1; i++) { if((i + 1) * 2 > d - 1) break; int ind = K - 2 - i; cur += cand[ind]; } ans = max(ans, cur); if(d >= 2) { cur = start + end; for(int i = 0; i < K - 1; i++) { if((i + 1) * 2 > d - 2) break; int ind = K - 2 - i; cur += cand[ind]; } ans = max(ans, cur); } printf("%d\n", ans); return 0; }
#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...