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 f first
#define s second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
ll v[100];
int N,K;
bool check(ll T){
if(T==0)return false;
int k=1;
ll v0=v[0];
for(int i=1;i<N;i++)if(v[i]+1LL-v0>T){
v0=v[i];
k++;
}
return k<=K;
}
int main(){
cin>>N>>K;
for(int i=0;i<N;i++)cin>>v[i];
ll x=-1;
for(ll b=v[N-1]-v[0]+1LL;b>=1LL;b/=2LL)
while(!check(x+b))x+=b;
x++;
ll v0=v[0];
ll s=0;
for(int i=1;i<N;i++)
if(v[i]+1-v0>x){
s+=v[i-1]+1-v0;
v0=v[i];
}
s+=v[N-1]+1-v0;
cout<<s;
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... |