Submission #435196

#TimeUsernameProblemLanguageResultExecution timeMemory
435196SupersonicStove (JOI18_stove)C++14
100 / 100
34 ms2380 KiB
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3") bool pc(pair<int,int> a,pair<int,int> b){ return a.second-a.first<b.second-b.first; } int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); int n,k;cin>>n>>k;vector<pair<int,int>> v; int pv;cin>>pv; for(int i=1;i<n;i++){int k;cin>>k;v.push_back({pv,k});pv=k;} sort(v.rbegin(),v.rend(),pc); //for(auto i:v){cerr<<i.first<<' '<<i.second<<endl;} long long s=n,r=n; while(r>k){ int a,b;tie(a,b)=v.back();v.pop_back();r--; s+=(long long)b-(a+1); } cout<<s<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...