Submission #52614

#TimeUsernameProblemLanguageResultExecution timeMemory
52614snat123Stove (JOI18_stove)C++14
100 / 100
30 ms11024 KiB
#include<bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k, res=0, cnt; cin >> n >> k; if(k==n){ cout << n; return 0; } res=n; cnt=n; long long a[n]; for(int i=0; i<n; i++) cin >> a[i]; vector<int>v; for(int i=1; i<n; i++){ v.push_back(a[i]-a[i-1]-1); } sort(v.begin(), v.end()); for(int i=0; i<v.size(); i++){ res+=v[i]; cnt--; if(cnt==k) break; } cout << res; return 0; }

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:23:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<v.size(); i++){
                  ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...