Submission #170261

#TimeUsernameProblemLanguageResultExecution timeMemory
170261AkashiStove (JOI18_stove)C++14
100 / 100
27 ms2168 KiB
#include <bits/stdc++.h> using namespace std; int n, k; int a[100005], b[100005]; int main() { scanf("%d%d", &n, &k); --k; int Sum = 0, Max = 0, Min = 2e9; for(int i = 1; i <= n ; ++i){ scanf("%d", &a[i]); if(i > 1) b[i] = a[i] - a[i - 1] - 1; Max = max(Max, a[i]); Min = min(Min, a[i]); } Sum = Max - Min + 1; sort(b + 1, b + n + 1); for(int i = n; i > n - k ; --i) Sum -= b[i]; printf("%d", Sum); return 0; }

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:8:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~
stove.cpp:13:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
         ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...