이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define len(x) (int)x.size()
#define x first
#define y second
using pii = pair<int, int>;
template <typename T1, typename T2>
ostream &operator<<(ostream &_o, pair<T1, T2> _a)
{
_o << _a.x << " " << _a.y;
return _o;
}
int n, k;
int main()
{
ios::sync_with_stdio(0), cin.tie(0);
cin >> n >> k;
priority_queue<int> dif;
int last;
cin >> last;
last++;
for (int i = 1; i < n; i++)
{
int a, b;
cin >> a;
b = a + 1;
dif.push(-(a - last));
last = b;
}
int res = 0;
while(len(dif) > k - 1)
{
res += -dif.top();
dif.pop();
}
cout << res + n << "\n";
}
/*
3 2
1
3
6
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |