이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
//typedef long long ll;
///typedef unsigned long long ull;
typedef pair<int,int> pi;
//typedef pair<long long,long long> pl;
#define all(s) s.begin(),s.end()
#define F first
#define S second
#define sz(a) a.size()
#define int long long
//const ll mod = 998244353;
//const ll mod1 = 1e9+7;
//const ll INF = 1e18;
const int N = 100200;
const int inf = 1e9+200;
int n,k;
int a[N];
vector<int> p;
int ans=0;
void solve() {
cin>>n>>k;
for(int i=1;i<=n;++i) {
cin>>a[i];
}
a[n+1]=inf;
for(int i=1,j=1;i<=n;++i) {
if(a[i]+1!=a[i+1]) {
p.push_back(a[i+1]-a[i]-1);
ans+=(a[i]-a[j]+1);
j=i+1;
}
}
sort(all(p));
int cnt=sz(p)-k;
for(auto u:p) {
if(cnt>0) {
ans+=u;
--cnt;
}
else {
break;
}
}
cout<<ans<<'\n';
}
signed main() {
ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
int T=1;
//cin>>T;
while(T--) {
solve();
}
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... |