Submission #12135

#TimeUsernameProblemLanguageResultExecution timeMemory
12135gs13105격자 보존하기 (GA9_preserve)C++98
52 / 100
32 ms1868 KiB
#include <stdio.h> #include <algorithm> int arr[100000]; int sor[100000]; inline bool cmp(const int &a,const int &b) { return a>b; } inline int mn(int a,int b) { return a<b?a:b; } inline int mx(int a,int b) { return a>b?a:b; } int main() { int n,k,d,r=0,i; scanf("%d%d%d",&n,&k,&d); for(i=0;i<k;i++) scanf("%d",&arr[i]); if(k==1) { if(d==1) printf("%d",mx(arr[0]-1,n-arr[0])); else printf("%d",n-1); return 0; } if(d>=2*k) { printf("%d",n-k); return 0; } for(i=0;i<k-1;i++) sor[i]=arr[i+1]-arr[i]-1; std::sort(sor,sor+k-1,cmp); if(d%2) { for(i=0;i<(d-1)/2;i++) r+=sor[i]; r+=mx(arr[0]-1,n-arr[k-1]); } else { for(i=0;i<d/2-1;i++) r+=sor[i]; r+=mx(arr[0]-1+n-arr[k-1],sor[d/2-1]); } printf("%d",r); 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...