# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1273257 | nlhuy | Stove (JOI18_stove) | C++20 | 1 ms | 568 KiB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define Task "test"
typedef pair<int,int>ii;
const int MOD = 1e9+7;
const int INF = 1e9+7;
const int Maxn = 1e5+7;
const int di[] = {0, 0, -1, 1};
const int dj[] = {-1, 1, 0, 0};
int n,k;
int sum;
int a[Maxn];
bool check(int x){
int d=k;
sum=0;
for(int i=1;i<=n;i++){
if (d==0) return false;
int ed=a[i]+x;
int l=i,r=n,pos=i;
while(l<=r){
int g=(l+r)/2;
if (a[g]+1<=ed) pos=g,l=g+1;
else r=g-1;
}
sum+=a[pos]+1-a[i];
i=pos;
d--;
}
return true;
}
void run_case(){
cin>>n>>k;
for(int i=1;i<=n;i++) cin>>a[i];
int l=1,r=a[n],ans;
while(l<=r){
int g=(l+r)/2;
if (check(g)) ans=sum,r=g-1;
else l=g+1;
}
cout<<ans;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
if (fopen(Task ".inp", "r"))
{
freopen(Task ".inp", "r", stdin);
freopen(Task ".out", "w", stdout);
}
int t = 1;
//cin >> t;
while(t--){
run_case();
}
}
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... |