이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pll pair<ll, ll>
#define pb push_back
#define bp pop_back
#define ades ios_base::sync_with_stdio(false); cin.tie(NULL);
ll N, M, a[100010], ans;
bool bener[100010];
pair<ll, ll> ada[100010];
int main(){
cin >> N >> M;
for(int i = 1; i<= N; i++){
cin >> a[i];
}
for(int i = 1; i< N; i++){
ada[i].fi = a[i+1]-a[i];
ada[i].se = i;
}
sort(ada+1, ada+N);
if(N <= M){
// for(int i = 1; i< N; i++){
// if(a[i] == a[i+1]){
// ans++;
// }
// else{
// ans++;
// }
// }
cout << N << endl;
return 0;
}
for(int i = 1; i<= N-M; i++){
bener[ada[i].se] = true;
// cout << ada[i].se << endl;
}
for(int i = 1; i<= N; i++){
if(bener[i]){
ans += a[i+1]-a[i];
}
else{
ans++;
}
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |