Two-point search + some tricks
1#include <iostream>2 using namespacestd;3 4 Const intmaxn=100000+Ten;5 intn,r[maxn],left[maxn],right[maxn];//because no calculation scheme, so you can press "1~r[i" and "r[i]+1~p" each take a few points, then did not think of this with set class write a time-consuming ~ ~ ~ (>_ <) ~ ~ ~6 7 BOOLOkintp)8 {9 intx=r[1],y=p-r[1];Tenleft[1]=x; right[1]=0; One for(intI=2; i<=n;i++) A { - if(i&1) - { theRight[i]=min (y-right[i-1],r[i]);//Odd guard first take the right. -left[i]=r[i]-right[i];//Look at the left to a few - } - Else + { -Left[i]=min (x-left[i-1],r[i]);//Even the guard first take the left. +right[i]=r[i]-left[i];//look at the right to a few A } at } - returnleft[n]==0;//The Nth guard on the left is 0 o'clock - } - - intMain () - { in while(cin>>n&&N) - { to for(intI=1; i<=n;i++) +Cin>>R[i]; - if(n==1) {cout<<r[1]<<endl;Continue;} This place pits me. ther[n+1]=r[1]; * intL=0, r=0; $ for(intI=1; i<=n;i++) L=max (l,r[i]+r[i+1]);Panax Notoginseng if(n&1) - { the for(intI=1; i<=n;i++) R=max (r,r[i]*3); + while(l<R) A { the intM= (L+R)/2; + if(OK (M)) R=M; - Elsel=m+1; $ } $ } -cout<<l<<Endl; - } the}
Uva Great Wall guard--1335-beijing guards