#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,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});
}
for(int i=1; i<n ;i++){
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;
}
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |