Submission #127303

#TimeUsernameProblemLanguageResultExecution timeMemory
127303ClementimeStove (JOI18_stove)C++17
0 / 100
2 ms376 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define FOR(i, l, r) for(ll i = l; i <= r; i++) ll a[100005], val[100005]; pair<ll, ll> p[100005]; bool tmp(pair<ll, ll> A, pair<ll, ll> B){ if(A.first != B.first) return A.first < B.first; else return A.second <= B.second; } int main(){ ll n, k; cin >> n >> k; FOR(i, 0, n - 1){ cin >> a[i]; } FOR(i, 0, n - 2){ val[i] = a[i + 1] - a[i]; p[i].first = val[i]; p[i].second = i; } sort(p, p + n - 1, tmp); set<ll> myset; ll num = 0; for(ll i = n - 2; i >= 0; i--){ if(num != k - 1){ num++; myset.insert(p[i].second); } } ll ans = 0; ll pos = 0; for(set<ll> :: iterator it = myset.begin(); it != myset.end(); it++){ ans += (a[*it] - a[pos]); pos = *it + 1; } if(k == 1){ cout << a[n - 1] - a[0] + 1; } else cout << ans + k; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...