이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
#define ll long long
using namespace std;
const int maxn = 1e5 + 10;
int n , k , a[maxn];
int cal(int x){
int j = 1 , cnt = 1;
for(int i = 1 ; i <= n ; i ++){
if(a[i] - a[j] + 1 <= x) continue;
j = i;
++cnt;
}
return cnt;
}
int32_t main()
{
cin.tie(0)->sync_with_stdio(0);
// if(fopen(".inp" , "r")){
// freopen(".inp" , "r" , stdin);
// freopen(".out" , "w" , stdout);
// }
cin >> n >> k;
for(int i = 1 ; i <= n ; i ++) cin >> a[i];
int l = 0 , r = 1e9 + 1 , ans = 1e9;
// cout << cal(3) << "\n";
while(l <= r){
int mid = (l + r) / 2;
if(cal(mid) <= k) ans = mid , r = mid - 1;
else l = mid + 1;
}
// cout << ans << " ";
int res = 0 , j = 0;
for(int i = 1 ; i <= n ; i = j + 1){
while(a[j + 1] - a[i] + 1 <= ans && j < n){
++j;
}
res += a[j] - a[i] + 1;
// cout << i << " " << j << '\n';
}
cout << res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |