Submission #41099

#TimeUsernameProblemLanguageResultExecution timeMemory
41099bugmenot111Stove (JOI18_stove)C++14
100 / 100
30 ms1288 KiB
#include <cstdio> #include <algorithm> #define MAXN 100100 int diff[MAXN], a[MAXN]; int main(void) { int n, k; scanf("%d%d", &n, &k); for(int i = 0; i < n; i++) scanf("%d", &a[i]); int ans = a[n - 1] - a[0] + 1; for(int i = 1; i < n; i++) diff[i] = a[i] - a[i - 1]; std::sort(diff + 1, diff + n, std::greater<int>()); for(int i = 1; i < k; i++) ans -= diff[i] - 1; printf("%d\n", ans); return 0; }

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:7:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &k);
                       ^
stove.cpp:8:47: 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...