Submission #1033637

#TimeUsernameProblemLanguageResultExecution timeMemory
1033637fimhStove (JOI18_stove)C++17
100 / 100
17 ms2316 KiB
#include <bits/stdc++.h> #define int long long #define fi first #define pll pair<long long, long long> #define se second #define isz(a) (int)a.size() using namespace std; const long long inf = 1e18; const int maxn = 1e5 + 5; const int mod = 1e9 + 7; int n, k; int a[maxn]; void subfull(){ priority_queue<int> pq; for (int i = 2; i <= n; ++i) pq.push(a[i] - a[i - 1]); int ans = a[n] - a[1] + 1; int cnt = 1; while (cnt < k){ int x = pq.top(); pq.pop(); ans -= x - 1; ++cnt; } cout << ans; } void solve(){ cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; subfull(); } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...