이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
_____ __ ___ __ _
/ ___/____ / /________ _ / | / /__(_)___ ____ _
\__ \/ __ \/ / ___/ __ `/ ______ / /| | / //_/ / __ \/ __ `/
___/ / /_/ / / / / /_/ / /_____/ / ___ |/ ,< / / / / / /_/ /
/____/\____/_/_/ \__,_/ /_/ |_/_/|_/_/_/ /_/\__,_/
*/
#include <bits/stdc++.h>
using namespace std;
int n,k;
int a[100001];
vector<int> ve;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
int res = a[n] - a[1] + 1;
int tru = 0;
for (int i = 1; i <= n - 1; i++) ve.push_back(a[i + 1] - (a[i] + 1));
sort(ve.begin(), ve.end());
k--;
for (int i = ve.size() - 1; i >= 0; i--)
{
if (k == 0) break;
k--;
tru += ve[i];
};
cerr << res << " " << tru << '\n';
cout << res - tru;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |