Submission #873291

#TimeUsernameProblemLanguageResultExecution timeMemory
873291AndreibatmanStove (JOI18_stove)C++14
100 / 100
58 ms5956 KiB
#include <bits/stdc++.h> using namespace std; long long n,k,i,v[100010],timp; map<long long,long long>fr,fr2; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>k; for(i=1;i<=n;i++) { cin>>v[i]; if(i>1) fr[-(v[i]-v[i-1])]++; } k--; for(auto it:fr) { if(k==0) break; if(it.first==-1) continue; fr2[it.first]+=min(k,it.second); k-=min(k,it.second); } timp=1; for(i=2;i<=n;i++) { if(v[i]-v[i-1]==1) timp++; else { if(!fr2[v[i-1]-v[i]]) timp+=v[i]-v[i-1]; else { fr2[v[i-1]-v[i]]--; timp++; } } } cout<<timp; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...