Submission #127211

#TimeUsernameProblemLanguageResultExecution timeMemory
127211nhimnam120Stove (JOI18_stove)C++14
100 / 100
88 ms2812 KiB
#include<bits/stdc++.h> using namespace std; vector<long long> inp; vector<long long> pro; signed main(){ long long n,k; cin >> n >> k; for(int i=1;i<=n;i++){ long long a; cin >> a; inp.push_back(a); } long long diff=1; sort(inp.begin(),inp.end()); for(int i=0;i<inp.size()-1;i++){ if(inp[i+1]-inp[i]>1){ diff++; pro.push_back(inp[i+1]-inp[i]-1); } } long long match=diff-k; sort(pro.begin(),pro.end()); if(match<=0){ cout << n; return 0; } long long ans=n; for(int i=0;i<match;i++){ ans+=pro[i]; } cout << ans; }

Compilation message (stderr)

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