이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
#define see(x) cout<<#x<<"="<<x<<"\n";
#define endl "\n"
using namespace std;
const int N = 1e5+5;
int n, k, t[N];
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
/*
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
*/
cin >> n >> k;
vector <pair <int, int>> stop;
for (int i = 0; i < n; i ++) {
cin >> t[i];
}
for (int i = 0; i < n; i ++) {
if (i + 1 < n) {
stop.push_back({t[i+1] - t[i], t[i]+1});
}
}
sort(stop.rbegin(), stop.rend());
vector <int> v;
for (int i = 0; i < k - 1; i ++) {
v.push_back(stop[i].second);
}
v.push_back(t[n-1] + 1);
sort(v.begin(), v.end());
int flag = 0, res = 0, pos = 0;
for (int i = 0; i < n; i ++) {
if (v[pos] < t[i]) {
pos ++;
flag = 0;
}
if (!flag) {
res += v[pos] - t[i];
flag = 1;
}
}
cout << res << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |