Submission #12789

#TimeUsernameProblemLanguageResultExecution timeMemory
12789woqja125격자 보존하기 (GA9_preserve)C++98
17 / 100
348 ms1868 KiB
#include<stdio.h> #include<algorithm> int p[100001]; int dat[100010]; int main() { int n, d, k, i, j, c = -1, t, a=0; scanf("%d%d%d", &n, &d, &k); for(i=1; i<=k; i++)scanf("%d", p+i); for(i=1; i<=k; i+=j) { dat[++c] = p[i] - p[i-1] - 1; for(j=0; i+j<=k && p[i]+j == p[i+j]; j++); } dat[++c] = n-p[k]; std::sort(dat+1, dat+c); a=0; for(i=1; i*2<=d && i<c; i++) a += dat[c-i]; if(d>=1) { t=dat[0] > dat[c] ? dat[0]:dat[c]; for(i=1; i*2+1<=d && i<c; i++) t += dat[c-i]; if(t>a) a = t; } if(d>=2) { t=dat[0] + dat[c]; for(i=1; i*2+2<=d && i<c; i++) t += dat[c-i]; if(t>a) a = t; } printf("%d", a); 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...