이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#ifdef LOCAL
#include "D:\debug.h"
#else
#define cebug(...) "anHiepORZ"
#endif
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
//less: set
//less_equal: multiset (ko dung dc ham ...)
#define fi first
#define se second
#define pb push_back
//COUNTDOWN: 9 days left
//COUNTDOWN: 9 days left
//COUNTDOWN: 9 days left
//COUNTDOWN: 9 days left
//COUNTDOWN: 9 days left
//COUNTDOWN: 9 days left
//COUNTDOWN: 9 days left
//COUNTDOWN: 9 days left
#define int long long
const int N = 1e5 + 10;
const int mod = 1e9 + 7;
const int oo = 1e18;
int n, k;
int a[N];
void solve(){
cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> a[i];
int s = 1;
int ans = 0;
vector<int> blk;
int sm = 0;
for(int i = 1; i <= n ; i++){
if(a[i] + 1 != a[i + 1]){
ans += (i - s + 1);
sm++;
if(i != n) blk.push_back(a[i + 1] - a[i] - 1);
s = i + 1;
}
}
int need = sm - k;
if(need <= 0) cout << ans;
else{
sort(blk.begin(), blk.end());
for(int i = 0; i < need; i++) ans+= blk[i];
cout << ans;
}
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tc; tc = 1;
while(tc--)
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... |