이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n, k;
vector<int> times;
vector<int> diff;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k;
times.resize(n), diff.resize(n - 1);
for (int &t : times) {
cin >> t;
}
sort(times.begin(), times.end());
for (int i = 0; i + 1 < n; i++) {
diff[i] = times[i + 1] - times[i];
}
int ans = n;
int k_req = n;
sort(diff.rbegin(), diff.rend());
while (k_req > k) {
ans += diff.back() - 1;
k_req--;
diff.pop_back();
}
cout << ans << 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... |