Submission #689365

#TimeUsernameProblemLanguageResultExecution timeMemory
689365AcanikolicStove (JOI18_stove)C++14
100 / 100
23 ms3268 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const ll mod = 1e9+7; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n,k; cin >> n >> k; vector<ll>a(n),b; for(ll i=0;i<n;i++) cin >> a[i]; for(ll i=1;i<n;i++) b.push_back(a[i]-a[i-1]); if(k>=n) { cout << n; return 0; } if(k==1) { cout << a[n-1]+1-a[0]; return 0; } ll R=k; ll treba=n-k; sort(b.begin(),b.end()); for(ll i=0;i<treba;i++) { R+=b[i]; // cout << b[i] << endl; } cout << R; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...