Submission #127220

#TimeUsernameProblemLanguageResultExecution timeMemory
127220nhimnam120Stove (JOI18_stove)C++14
100 / 100
28 ms1652 KiB
#include<bits/stdc++.h> #pragma optimize(Ofast) using namespace std; vector<int> inp; vector<int> pro; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n,k; cin >> n >> k; for(int i=1;i<=n;i++){ int a; cin >> a; inp.push_back(a); } int 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); } } int match=diff-k; sort(pro.begin(),pro.end()); if(match<=0){ cout << n; return 0; } int ans=n; for(int i=0;i<match;i++){ ans+=pro[i]; } cout << ans; }

Compilation message (stderr)

stove.cpp:2:0: warning: ignoring #pragma optimize  [-Wunknown-pragmas]
 #pragma optimize(Ofast)
 
stove.cpp: In function 'int main()':
stove.cpp:18: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...