Submission #20148

#TimeUsernameProblemLanguageResultExecution timeMemory
20148kdh9949격자 보존하기 (GA9_preserve)C++98
100 / 100
34 ms1864 KiB
#include <cstdio> #include <algorithm> using namespace std; int l, n, k, a[100010], s[100010]; int main(){ scanf("%d%d%d", &l, &n, &k); if(k > 2 * n) k = 2 * n; for(int i = 0; i < n; i++) scanf("%d", a + i); sort(a, a + n); for(int i = 1; i < n; i++) s[i] = a[i] - a[i - 1] - 1; sort(s + 1, s + n); reverse(s + 1, s + n); for(int i = 1; i < n; i++) s[i] += s[i - 1]; if(k == 1) printf("%d", max(a[0] - 1, l - a[n - 1])); else if(k % 2) printf("%d", max(s[k / 2] + max(a[0] - 1, l - a[n - 1]), s[k / 2 - 1] + a[0] - 1 + l - a[n - 1])); else printf("%d", max(s[k / 2], s[k / 2 - 1] + a[0] - 1 + l - a[n - 1])); }
#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...