Submission #92129

#TimeUsernameProblemLanguageResultExecution timeMemory
92129tjrwodnjs999격자 보존하기 (GA9_preserve)C++11
100 / 100
24 ms2112 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])); }

Compilation message (stderr)

preserve.cpp: In function 'int main()':
preserve.cpp:8:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d", &l, &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~
preserve.cpp:10:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 0; i < n; i++) scanf("%d", a + i);
                                ~~~~~^~~~~~~~~~~~~
#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...