Submission #593495

#TimeUsernameProblemLanguageResultExecution timeMemory
593495starchanStove (JOI18_stove)C++17
100 / 100
22 ms2896 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define in pair<int, int> #define f first #define s second #define pb push_back #define pob pop_back #define INF (int)1e17 #define MX (int)3e5+5 #define fast() ios_base::sync_with_stdio(false); cin.tie(NULL) signed main() { fast(); int n, k; cin >> n >> k; vector<int> t(n+1); for(int i = 1; i <= n; i++) cin >> t[i]; vector<int> diff(n); for(int i = 1; i < n; i++) diff[i] = t[i+1]-t[i]-1; int ans = t[n]-t[1]+1; diff[0] = INF; sort(diff.rbegin(), diff.rend()); for(int i = 1; i < k; i++) ans-=diff[i]; cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...