이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k; cin>>n>>k;
vector<int> t(n);
vector<int> off(n,0);
vector<pair<int,int>> diffs;
for (int i=0; i<n; i++) {
cin>>t[i];
if (i>0) {
diffs.push_back({t[i]-t[i-1]+1, i-1});
}
}
sort(diffs.begin(), diffs.end(), greater<pair<int,int>>());
for (int i=0; i<k-1; i++) {
off[diffs[i].second]=1;
}
off[n-1]=1;
int ind=0;
long long ans=0;
while (ind<n) {
int start=ind;
while (!off[ind]) {
ind++;
}
ans+=(t[ind]-t[start]+1);
ind++;
}
cout << ans;
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... |