Submission #651333

#TimeUsernameProblemLanguageResultExecution timeMemory
651333ayallaStove (JOI18_stove)C++14
100 / 100
24 ms2376 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define int long long int #define endl '\n' #define pb push_back #define pi pair<int, int> #define pii pair<int, pi> #define fir first #define sec second #define MAXN 500001 #define mod 1000000007 signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k; cin >> n >> k; vector<int> v(n); priority_queue<int, vector<int>, greater<int>> pq; for (int i = 0; i < n; i++) { cin >> v[i]; if (i >= 1) pq.push((v[i] - v[i - 1]) - 1); } int g = n, ans = n; while (g > k) { ans += pq.top(); pq.pop(); g--; } cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...