Submission #315647

#TimeUsernameProblemLanguageResultExecution timeMemory
315647nandonathanielStove (JOI18_stove)C++14
100 / 100
22 ms1920 KiB
#include<bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int n,k,prv,first,a; vector<int> v; cin >> n >> k; for(int i=1;i<=n;i++){ cin >> a; if(i==1)first=a; if(i>1)v.push_back(a-prv-1); prv=a; } int ans=prv-first+1; //take k-1 maximum number sort(v.begin(),v.end()); reverse(v.begin(),v.end()); for(int i=0;i<k-1;i++)ans-=v[i]; cout << ans << '\n'; return 0; }

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:15:13: warning: 'first' may be used uninitialized in this function [-Wmaybe-uninitialized]
   15 |  int ans=prv-first+1;
      |          ~~~^~~~~~
stove.cpp:15:13: warning: 'prv' may be used uninitialized in this function [-Wmaybe-uninitialized]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...