# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1243989 | snowysmo | 구경하기 (JOI13_watching) | C++20 | 0 ms | 0 KiB |
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const int mx = 2e5+7;
ll n, p, q, a[mx];
bool check(ll x){
ll a=p, b=q;
bool cn=1;
for(ll i=1;i<=n;i++){
ll xx=a[i+1]-a[i]+1, yy=a[i+2]-a[i]+1;
if(2*x-yy >= x-xx && x!=0) x--, i++;
else if(2*x-yy >= x-xx && x==0) y--, i+=2;
else if(2*x-yy < x-xx && y!=0) y--, i+=2;
else if(2*x-yy < x-xx && y==0) x--, i++;
else{ cn=0; break; }
}
return cn;
}
ll binser(ll l, ll r){
ll mid, ans=1e9+7;
while(l<=r){
mid=(l+r)/2;
if(check(mid)) ans=min(ans, mid), r=mid-1;
else l=mid+1;
}
return ans;
}
int main(){
cin>>n>>p>>q;
ll temp = p+2*q;
ll ans=0;
for(ll i=1;i<=n;i++) cin>>a[i];
for(ll i=2;i<=n;i++) ans+=abs(a[i]-a[i-1]);
ll x = ans/temp+1;
cout<<binser(1, x)<<endl;
return 0;
}