Submission #814830

#TimeUsernameProblemLanguageResultExecution timeMemory
814830CookieStove (JOI18_stove)C++14
100 / 100
18 ms3236 KiB
#include<bits/stdc++.h> #include<fstream> using namespace std; ifstream fin("FEEDING.INP"); ofstream fout("FEEDING.OUT"); #define sz(a) (int)a.size() #define ll long long #define pb push_back #define forr(i, a, b) for(int i = a; i < b; i++) #define dorr(i, a, b) for(int i = a; i >= b; i--) #define ld long double #define vt vector #include<fstream> #define fi first #define se second #define pll pair<ll, ll> #define pii pair<int, int> const ld PI = 3.14159265359; using u128 = __uint128_t; //const int x[4] = {1, -1, 0, 0}; // int y[4] = {0, 0, 1, -1}; const ll mod = 1e15 + 7, inf = 1e16; const int mxn = 2e5 + 5; int n, k; ll a[mxn + 1]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; for(int i = 1; i <= n; i++){ cin >> a[i]; } vt<ll>seg; for(int i = 1; i < n; i++){ seg.pb(a[i + 1] - a[i] - 1); } sort(seg.rbegin(), seg.rend()); ll ans = a[n] + 1 - a[1]; for(int i = 0; i < k - 1; i++){ ans -= seg[i]; } cout << ans; return(0); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...