이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FOD(i, b, a) for(int i = (b); i >= (a); --i)
#define ll long long
#define fi first
#define se second
using namespace std;
const int N = 1e5 + 5;
int n, k;
int t[N], d[N];
void solve(int tc) {
cin >> n >> k;
FOR(i, 1, n) cin >> t[i];
FOR(i, 1, n - 1) d[i] = t[i + 1] - (t[i] + 1);
int ans = t[n] + 1 - t[1];
sort(d + 1, d + n, greater<int>());
for(int i = 1; i < k; ++i) {
ans -= d[i];
}
cout << ans;
return;
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int tc = 1;
// cin >> tc;
for(int i = 1; i <= tc; ++i) solve(tc);
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... |