Submission #219808

#TimeUsernameProblemLanguageResultExecution timeMemory
219808NightlightStove (JOI18_stove)C++14
100 / 100
39 ms1784 KiB
#include <bits/stdc++.h> using namespace std; int N, K; int best[100005]; int main() { scanf("%d %d", &N, &K); if(N == 1) { puts("1"); return 0; } int last, now, pertamax, terakhir; scanf("%d", &pertamax); last = pertamax; for(int i = 2; i < N; i++) { scanf("%d", &now); best[i - 1] = now - last - 1; last = now; } scanf("%d", &terakhir); best[N - 1] = terakhir - last - 1; sort(best + 1, best + N + 1, greater<int>()); int ans = terakhir - pertamax + 1; for(int i = 1; i < K; i++) { ans -= best[i]; } printf("%d", ans); }

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:8:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &N, &K);
   ~~~~~^~~~~~~~~~~~~~~~~
stove.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &pertamax);
   ~~~~~^~~~~~~~~~~~~~~~~
stove.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &now);
     ~~~~~^~~~~~~~~~~~
stove.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &terakhir);
   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...