Submission #958361

#TimeUsernameProblemLanguageResultExecution timeMemory
958361leo_2727Stove (JOI18_stove)C++17
100 / 100
19 ms2704 KiB
#include <algorithm> #include <fstream> #include <vector> #include <queue> #include <stack> #include <iostream> #include <cmath> #include <queue> #include <set> #include <string> #include <cstring> #include <map> #include <unordered_map> #include <unordered_set> #define F first #define S second #define PB push_back using namespace std; const long long MOD=1e9+7, INF=1e18; const int INFI=1e9; typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ii> vii; typedef vector<pair<int, ii>> viii; typedef vector<vii> vvii; typedef vector<ll> vll; typedef vector<vll> vvll; bool cmp(const ii& x, const ii& y) { return x.F>y.F; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin>>n>>k; ll ans=0; vi ar(n+1, 0); vii dif(n-1, {0, 0}); bool mark[n+1]; memset(mark, false, n+1); for(int i=1;i<=n;i++) cin>>ar[i]; for(int i=2;i<=n;i++) dif[i-2]={ar[i]-ar[i-1], i}; sort(dif.begin(), dif.end(), cmp); for(int i=0;i<k-1;i++) mark[dif[i].S]=true; int inicio=ar[1]; for(int i=1;i<=n;i++){ if(mark[i]){ ans+=ar[i-1]+1-inicio; inicio=ar[i]; } } ans+=ar[n]+1-inicio; cout<<ans<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...