Submission #76858

#TimeUsernameProblemLanguageResultExecution timeMemory
76858VardanyanStove (JOI18_stove)C++14
50 / 100
3 ms764 KiB
#include <bits/stdc++.h> using namespace std; const int N = 5007; long long a[N]; long long dif[N]; int main(){ int n,k; scanf("%d%d",&n,&k); for(int i = 1;i<=n;i++){ scanf("%lld",&a[i]); if(i>1) dif[i] = a[i]-a[i-1]; } sort(dif+1,dif+1+n); reverse(dif+1,dif+1+n); long long c = 0; for(int i = 1;i<=k-1;i++)c+=dif[i]; c = a[n]-a[1]+k-c; printf("%lld\n",c); 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:10:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%lld",&a[i]);
             ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...