Submission #159869

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

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:9: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...