# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
831301 | manhtuan22007 | Stove (JOI18_stove) | C++14 | 1 ms | 212 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 << " ";
ll 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;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |