Submission #127315

#TimeUsernameProblemLanguageResultExecution timeMemory
127315ClementimeStove (JOI18_stove)C++17
100 / 100
92 ms4248 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); ll ans = 0; FOR(i, 0, n - k - 1){ ans += p[i].first; } cout << ans + k; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...