# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1113284 | hpesoj | Stove (JOI18_stove) | C++17 | 26 ms | 3388 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define int long long
#define pi pair<int, int>
#define ppi pair<pi, int>
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mp make_pair
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << '\n'
#define debug2(x, y) cout << #x << ": " << x << ' ' << #y << ": " << y << '\n'
#define debug3(x, y, z) cout << #x << ": " << x << ' ' << #y << ": " << y << ' ' << #z << ": " << z << '\n'
using namespace std;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
const int inf = 1e18+5, mod = 1000000007;
signed main(){
ios::sync_with_stdio(0), cin.tie(0);
int n, k; cin >> n >> k;
int t[n+1];
for(int i = 1; i <= n; i++) cin >> t[i];
int ans = n;
priority_queue <int, vector <int>, greater <int>> pq;
for(int i = 2; i <= n; i++) if(t[i] - t[i-1] > 1) pq.push(t[i] - t[i-1] - 1);
while(pq.size() >= k) ans += pq.top(), pq.pop();
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |