이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define pf push_front
using namespace std;
#define F first
#define S second
typedef long long ll;
#define pii pair <int, int>
#define pll pair <ll, ll>
typedef long double ld;
const ll N = 1e5 + 10, len = 316;
const ll mod = 1e9 + 7;
int arr[N];
int main() {
// ios::sync_with_stdio(false);
// cin.tie(NULL);
int n, k, ans = 0;
cin >> n >> k;
for(int i = 0; i < n; i++){
cin >> arr[i];
}
sort(arr, arr + n);
set <int> st;
int cur = arr[0], fir = arr[0], cnt = 1;
for(int i = 1; i < n; i++){
if(arr[i] - cur <= 1) cur = arr[i];
else{
ans += (cur - fir + 1);
cnt++;
st.insert({arr[i] - cur - 1});
cur = fir = arr[i];
}
}
ans += (cur - fir + 1);
while(cnt > k){
ans += *st.begin();
st.erase(st.begin());
cnt--;
}
cout << ans;
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... |