#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;
}
priority_queue<pair<mob,int>,vector<pair<mob,int> >,greater<pair<mob,int> > >cave;
int cp[100001],cs[100001];
bool vis[100001];
mob val[100001];
bool solve(ll s){
ll blood=s;
for(int i=1; i<=n ;i++) cp[i]=cs[i]=i;
for(int i=1; i<=n ;i++) vis[i]=false;
while(!cave.empty()) cave.pop();
for(int i=1; i<k ;i++){
val[i]={x[i+1]-x[i],s};
cave.push({val[i],i});
}
for(int i=n; i>k ;i--){
val[i]={x[i]-x[i-1],s};
cave.push({val[i],i});
}
while(!cave.empty()){
auto cur=cave.top();cave.pop();
if(vis[cur.se] || val[cur.se].fi!=cur.fi.fi || val[cur.se].se!=cur.fi.se) continue;
vis[cur.se]=true;
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
val[cp[par]]=val[cp[par]]+val[cur.se];
cave.push({val[cp[par]],cp[par]});
}
}
return true;
}
void read(int& x){
char c=getchar();
while(c<48 || c>57) c=getchar();
x=0;
while(c>=48 && c<=57){
x=x*10+c-48;
c=getchar();
}
}
void read(ll& x){
char c=getchar();
while(c<48 || c>57) c=getchar();
x=0;
while(c>=48 && c<=57){
x=x*10+c-48;
c=getchar();
}
}
int main(){
ios::sync_with_stdio(false);
read(n);read(k);read(t);
for(int i=1; i<=n ;i++) read(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 |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 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 |
376 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 |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 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 |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
7 ms |
376 KB |
Output is correct |
23 |
Correct |
4 ms |
376 KB |
Output is correct |
24 |
Correct |
8 ms |
504 KB |
Output is correct |
25 |
Correct |
11 ms |
504 KB |
Output is correct |
26 |
Correct |
11 ms |
376 KB |
Output is correct |
27 |
Correct |
11 ms |
376 KB |
Output is correct |
28 |
Correct |
11 ms |
504 KB |
Output is correct |
29 |
Correct |
11 ms |
504 KB |
Output is correct |
30 |
Correct |
11 ms |
504 KB |
Output is correct |
31 |
Correct |
11 ms |
504 KB |
Output is correct |
32 |
Correct |
11 ms |
380 KB |
Output is correct |
33 |
Correct |
11 ms |
376 KB |
Output is correct |
34 |
Correct |
11 ms |
380 KB |
Output is correct |
35 |
Correct |
11 ms |
376 KB |
Output is correct |
36 |
Correct |
11 ms |
504 KB |
Output is correct |
37 |
Correct |
11 ms |
504 KB |
Output is correct |
38 |
Correct |
11 ms |
376 KB |
Output is correct |
39 |
Correct |
11 ms |
504 KB |
Output is correct |
40 |
Correct |
7 ms |
504 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 |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 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 |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
7 ms |
376 KB |
Output is correct |
23 |
Correct |
4 ms |
376 KB |
Output is correct |
24 |
Correct |
8 ms |
504 KB |
Output is correct |
25 |
Correct |
11 ms |
504 KB |
Output is correct |
26 |
Correct |
11 ms |
376 KB |
Output is correct |
27 |
Correct |
11 ms |
376 KB |
Output is correct |
28 |
Correct |
11 ms |
504 KB |
Output is correct |
29 |
Correct |
11 ms |
504 KB |
Output is correct |
30 |
Correct |
11 ms |
504 KB |
Output is correct |
31 |
Correct |
11 ms |
504 KB |
Output is correct |
32 |
Correct |
11 ms |
380 KB |
Output is correct |
33 |
Correct |
11 ms |
376 KB |
Output is correct |
34 |
Correct |
11 ms |
380 KB |
Output is correct |
35 |
Correct |
11 ms |
376 KB |
Output is correct |
36 |
Correct |
11 ms |
504 KB |
Output is correct |
37 |
Correct |
11 ms |
504 KB |
Output is correct |
38 |
Correct |
11 ms |
376 KB |
Output is correct |
39 |
Correct |
11 ms |
504 KB |
Output is correct |
40 |
Correct |
7 ms |
504 KB |
Output is correct |
41 |
Correct |
525 ms |
4212 KB |
Output is correct |
42 |
Correct |
28 ms |
636 KB |
Output is correct |
43 |
Correct |
155 ms |
1780 KB |
Output is correct |
44 |
Correct |
1787 ms |
6248 KB |
Output is correct |
45 |
Correct |
1796 ms |
6376 KB |
Output is correct |
46 |
Correct |
1767 ms |
6248 KB |
Output is correct |
47 |
Correct |
1933 ms |
6252 KB |
Output is correct |
48 |
Correct |
1841 ms |
6248 KB |
Output is correct |
49 |
Correct |
1834 ms |
6248 KB |
Output is correct |
50 |
Correct |
1767 ms |
6248 KB |
Output is correct |
51 |
Correct |
1818 ms |
6248 KB |
Output is correct |
52 |
Correct |
1810 ms |
6252 KB |
Output is correct |
53 |
Correct |
1819 ms |
6252 KB |
Output is correct |
54 |
Correct |
1787 ms |
6248 KB |
Output is correct |
55 |
Correct |
1717 ms |
6252 KB |
Output is correct |
56 |
Correct |
1837 ms |
6248 KB |
Output is correct |
57 |
Correct |
1777 ms |
6248 KB |
Output is correct |
58 |
Correct |
1805 ms |
6256 KB |
Output is correct |
59 |
Correct |
787 ms |
6252 KB |
Output is correct |
60 |
Correct |
1814 ms |
6312 KB |
Output is correct |
61 |
Correct |
1884 ms |
6252 KB |
Output is correct |
62 |
Correct |
1783 ms |
6252 KB |
Output is correct |
63 |
Correct |
1918 ms |
6248 KB |
Output is correct |
64 |
Correct |
1909 ms |
6252 KB |
Output is correct |
65 |
Correct |
1885 ms |
6252 KB |
Output is correct |
66 |
Correct |
1861 ms |
6252 KB |
Output is correct |
67 |
Correct |
1854 ms |
6252 KB |
Output is correct |
68 |
Correct |
1889 ms |
6256 KB |
Output is correct |
69 |
Correct |
1865 ms |
6252 KB |
Output is correct |