Submission #159868

#TimeUsernameProblemLanguageResultExecution timeMemory
159868dantoh000Stove (JOI18_stove)C++14
100 / 100
30 ms1784 KiB
#include <bits/stdc++.h> using namespace std; int main(){ int n,k; scanf("%d%d",&n,&k); int last; int x; scanf("%d",&last); int a[n]; int ct= 0; int ans = 0; for (int i = 1; i < n; i++) { scanf("%d",&x); a[ct++] = x-last-1; ans += x-last-1; last = x; } sort(a,a+n-1,greater<int>()); for (int i = 0; i < k-1; i++){ //printf("%d ",a[i]); ans -= a[i]; } printf("%d",ans+n); }

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:5: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:8:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&last);
     ~~~~~^~~~~~~~~~~~
stove.cpp:13:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&x);
         ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...