이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, l, r) for(ll i = l; i <= r; i++)
ll a[100005], val[100005];
pair<ll, ll> p[100005];
bool tmp(pair<ll, ll> A, pair<ll, ll> B){
if(A.first != B.first) return A.first < B.first;
else return A.second <= B.second;
}
int main(){
ll n, k;
cin >> n >> k;
FOR(i, 0, n - 1){
cin >> a[i];
}
FOR(i, 0, n - 2){
val[i] = a[i + 1] - a[i];
p[i].first = val[i];
p[i].second = i;
}
sort(p, p + n - 1, tmp);
set<ll> myset;
ll num = 0;
for(ll i = n - 2; i >= 0; i--){
if(num != k - 1){
num++;
myset.insert(p[i].second);
}
}
ll ans = 0;
ll pos = 0;
for(set<ll> :: iterator it = myset.begin(); it != myset.end(); it++){
ans += (a[*it] - a[pos]);
pos = *it + 1;
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |