Submission #12134

#TimeUsernameProblemLanguageResultExecution timeMemory
12134gs14004격자 보존하기 (GA9_preserve)C++98
100 / 100
32 ms1868 KiB
#include <cstdio> #include <algorithm> #include <vector> using namespace std; int seg[100005]; int lseg, rseg, a[100005]; int main(){ int l,n,d; scanf("%d %d %d",&l,&n,&d); for (int i=0; i<n; i++) { scanf("%d",&a[i]); if(i == 0) lseg = a[i] - 1; if(i == n-1) rseg = l - a[i]; if(i) seg[i-1] = (a[i] - a[i-1] - 1); } sort(seg,seg+n-1); reverse(seg,seg+n-1); int ans1 = 0; for (int i=0; i<n-1 && i<d/2; i++) { ans1 += seg[i]; } int ans2 = max(lseg,rseg); for (int i=0; i<n-1 && i<(d-1)/2; i++) { ans2 += seg[i]; } int ans3 = lseg + rseg; for (int i=0; i<n-1 && i<(d-2)/2; i++) { ans3 += seg[i]; } if(d == 1) printf("%d",max(ans1,ans2)); else printf("%d",max(ans1,max(ans2,ans3))); }
#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...