이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pii pair<int, int>
const ll mod = 1e9 + 7;
void solve() {
int n, k;
cin >> n >> k;
int arr[n + 1];
for (int i = 1; i <= n; i++)
cin >> arr[i];
vector<int> vals;
sort(arr + 1, arr + n + 1);
for (int i = 2; i <= n; i++)
vals.pb(arr[i] - arr[i - 1]);
int ans = 0;
sort(vals.begin(), vals.end());
for (int i = 0; i < n - k; i++)
ans += vals[i];
cout << ans + k;
}
int main() {
int t = 1;
// cin >> t;
while (t--) {
solve();
cout << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |