Submission #473623

#TimeUsernameProblemLanguageResultExecution timeMemory
473623pluto_ishStove (JOI18_stove)C++14
100 / 100
22 ms2236 KiB
#include <bits/stdc++.h> #define pb push_back #define ff first #define ss second using namespace std; typedef long long ll; typedef unsigned long long ull; const ll INF = (ll)1<<62; const ll MOD = 1e9+7; const int iINF = 1<<30; const double PI = 3.14159265359; void solve(){ int n, k; cin >> n >> k; vector<int> a(n), gap; for(int i=0;i<n;i++){ cin >> a[i]; if(i) gap.pb(a[i]-(a[i-1]+1)); } int ans = a[n-1]+1 - a[0]; sort(gap.rbegin(), gap.rend()); int parts = 1; for(int i=0;parts < k;i++){ //cout << gap[i] << " "; ans -= gap[i]; parts++; } cout << ans << "\n"; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; //cin >> t; while(t--){ solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...