Submission #573322

#TimeUsernameProblemLanguageResultExecution timeMemory
573322talant117408Stove (JOI18_stove)C++17
100 / 100
19 ms2264 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair <int, int> pii; typedef pair <ll, ll> pll; #define pb push_back #define mp make_pair #define all(v) (v).begin(),(v).end() #define sz(v) int((v).size()) #define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define endl '\n' int mod = 1e9+7; ll modulo(ll a) { return ((a % mod) + mod) % mod; } ll add(ll a, ll b) { return modulo(a + b); } ll mult(ll a, ll b) { return modulo(a * b); } ll binpow(ll a, ll b) { ll res = 1; while (b) { if (b&1) { res = mult(res, a); } a = mult(a, a); b >>= 1; } return res; } void solve() { int n, k; cin >> n >> k; vector <int> v(n); for (auto &to : v) cin >> to; vector <int> diff; for (int i = 0; i < n-1; i++) { diff.pb(v[i+1]-v[i]-1); } sort(all(diff)); int ans = v.back()-v[0]+1; while (k > 1) { k--; ans -= diff.back(); diff.pop_back(); } cout << ans; } int main() { do_not_disturb 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...