#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
int n,k;
ll t;
ll x[100001];
bool got[100001];
struct mob{
ll fi,se;
};
mob operator+(mob x,mob y){
ll a=max(x.fi,x.fi-x.se+y.fi);
ll b=x.se-x.fi+y.se-y.fi+a;
return (mob){a,b};
}
bool operator<(mob x,mob y){
bool sx=x.fi<x.se,sy=y.fi<y.se;
if(sx!=sy) return sx>sy;
if(x.fi<x.se) return x.fi<y.fi;
return x.se>y.se;
}
multiset<pair<mob,int> >cave;
int cp[100001],cs[100001];
mob val[100001];
bool solve(ll s){
ll blood=s;
for(int i=1; i<=n ;i++) cp[i]=cs[i]=i;
cave.clear();
for(int i=1; i<k ;i++){
val[i]={x[i+1]-x[i],s};
cave.insert({val[i],i});
}
for(int i=n; i>k ;i--){
val[i]={x[i]-x[i-1],s};
cave.insert({val[i],i});
}
for(int i=1; i<n ;i++){
auto cur=*cave.begin();
cave.erase(cave.begin());
int par=cur.se+(cur.se<k)-(cur.se>k);
cp[cs[cur.se]]=cp[par];
cs[cp[par]]=cs[cur.se];
if(cp[par]==k){//execute
blood-=cur.fi.fi;
if(blood<0) return false;
blood+=cur.fi.se;
}
else{//merge
cave.erase(cave.find({val[cp[par]],cp[par]}));
val[cp[par]]=val[cp[par]]+val[cur.se];
cave.insert({val[cp[par]],cp[par]});
}
}
return true;
}
int main(){
ios::sync_with_stdio(false);
cin >> n >> k >> t;
for(int i=1; i<=n ;i++){
cin >> x[i];
}
ll l=0,r=1e9/t+1;
while(l!=r){
ll mid=(l+r)/2;
if(solve(mid*t*2)) r=mid;
else l=mid+1;
}
cout << l << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
380 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
380 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
380 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
380 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
9 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
11 ms |
376 KB |
Output is correct |
25 |
Correct |
16 ms |
504 KB |
Output is correct |
26 |
Correct |
16 ms |
516 KB |
Output is correct |
27 |
Correct |
16 ms |
504 KB |
Output is correct |
28 |
Correct |
15 ms |
504 KB |
Output is correct |
29 |
Correct |
16 ms |
504 KB |
Output is correct |
30 |
Correct |
15 ms |
504 KB |
Output is correct |
31 |
Correct |
16 ms |
504 KB |
Output is correct |
32 |
Correct |
16 ms |
516 KB |
Output is correct |
33 |
Correct |
15 ms |
504 KB |
Output is correct |
34 |
Correct |
16 ms |
508 KB |
Output is correct |
35 |
Correct |
15 ms |
504 KB |
Output is correct |
36 |
Correct |
16 ms |
504 KB |
Output is correct |
37 |
Correct |
16 ms |
504 KB |
Output is correct |
38 |
Correct |
15 ms |
504 KB |
Output is correct |
39 |
Correct |
15 ms |
504 KB |
Output is correct |
40 |
Correct |
8 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
380 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
380 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
9 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
11 ms |
376 KB |
Output is correct |
25 |
Correct |
16 ms |
504 KB |
Output is correct |
26 |
Correct |
16 ms |
516 KB |
Output is correct |
27 |
Correct |
16 ms |
504 KB |
Output is correct |
28 |
Correct |
15 ms |
504 KB |
Output is correct |
29 |
Correct |
16 ms |
504 KB |
Output is correct |
30 |
Correct |
15 ms |
504 KB |
Output is correct |
31 |
Correct |
16 ms |
504 KB |
Output is correct |
32 |
Correct |
16 ms |
516 KB |
Output is correct |
33 |
Correct |
15 ms |
504 KB |
Output is correct |
34 |
Correct |
16 ms |
508 KB |
Output is correct |
35 |
Correct |
15 ms |
504 KB |
Output is correct |
36 |
Correct |
16 ms |
504 KB |
Output is correct |
37 |
Correct |
16 ms |
504 KB |
Output is correct |
38 |
Correct |
15 ms |
504 KB |
Output is correct |
39 |
Correct |
15 ms |
504 KB |
Output is correct |
40 |
Correct |
8 ms |
376 KB |
Output is correct |
41 |
Correct |
809 ms |
7188 KB |
Output is correct |
42 |
Correct |
42 ms |
632 KB |
Output is correct |
43 |
Correct |
231 ms |
2424 KB |
Output is correct |
44 |
Execution timed out |
2045 ms |
10744 KB |
Time limit exceeded |
45 |
Halted |
0 ms |
0 KB |
- |