I guess there's not much point in reminding you that Nvodsk winters aren't exactly hot. That increased the popularity of the public transport dramatically. The route of bus 62 has exactly n stops (stop 1 goes first on its way and stop n goes last). The stops are positioned on a straight line and their coordinates are 0 = x1 < x2 < ... < xn.
Each day exactly m people use bus 62. For each person we know the number of the stop where he gets on the bus and the number of the stop where he gets off the bus. A ticket from stop a to stop b (a < b) costs xb - xa rubles. However, the conductor can choose no more than one segment NOT TO SELL a ticket for. We mean that conductor should choose C and D (С <= D) and sell a ticket for the segments [A, C] and [D, B], or not sell the ticket at all. The conductor and the passenger divide the saved money between themselves equally. The conductor's "untaxed income" is sometimes interrupted by inspections that take place as the bus drives on some segment of the route located between two consecutive stops. The inspector fines the conductor by c rubles for each passenger who doesn't have the ticket for this route's segment.
You know the coordinated of all stops xi; the numbers of stops where the i-th passenger gets on and off, ai and bi (ai < bi); the fine c; and also pi — the probability of inspection on segment between the i-th and the i + 1-th stop. The conductor asked you to help him make a plan of selling tickets that maximizes the mathematical expectation of his profit.
The first line contains three integers n, m and c (2 ≤ n ≤ 1.5·105, 1 ≤ m ≤ 3·105, 1 ≤ c ≤ 104).
The next line contains n integers xi (0 ≤ xi ≤ 109, x1 = 0, xi < xi + 1) — the coordinates of the stops on the bus's route.
The third line contains n - 1 integer pi (0 ≤ pi ≤ 100) — the probability of inspection in percents on the segment between stop i and stop i + 1.
Then follow m lines that describe the bus's passengers. Each line contains exactly two integers ai and bi (1 ≤ ai < bi ≤ n) — the numbers of stops where the i-th passenger gets on and off.
Print the single real number — the maximum expectation of the conductor's profit. The answer will be considered correct if its relative or absolute error does not exceed 10 - 6.
3 3 10 0 10 100 100 0 1 2 2 3 1 3
90.000000000
10 8 187 0 10 30 70 150 310 630 1270 2550 51100 13 87 65 0 100 44 67 3 4 1 10 2 9 3 8 1 5 6 10 2 7 4 10 4 5
76859.990000000
A comment to the first sample:
The first and third passengers get tickets from stop 1 to stop 2. The second passenger doesn't get a ticket. There always is inspection on the segment 1-2 but both passengers have the ticket for it. There never is an inspection on the segment 2-3, that's why the second passenger gets away with the cheating. Our total profit is (0 + 90 / 2 + 90 / 2) = 90.
分析:题目意思中是针对每位乘客,可以选取一连续段不收票。问题转化为,m次询问,查找区间[a,b)内最大连续子序列和。
#include<cstdio>
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
const int N=150002;
template<class T>
inline void scan_d(T &ret){
char c;ret=0;
while((c=getchar())<'0'||c>'9');
while(c>='0'&&c<='9')ret=ret*10+(c-'0'),c=getchar();
}
struct node{
ll s,l,r,m;
}A[N<<2];
int x[N];
ll max(ll a,ll b){return a>b?a:b;}
node pushup(node L,node R){
node F;
F.s=L.s+R.s;
F.l=max(L.l,L.s+R.l);
F.r=max(R.r,L.r+R.s);
F.m=max(max(L.m,R.m),L.r+R.l);
return F;
}
void build(int l,int r,int rt){
if(l==r){A[rt].s=A[rt].l=A[rt].r=A[rt].m=x[l];return ;}
int m=(l+r)>>1;
build(lson);
build(rson);
A[rt]=pushup(A[rt<<1],A[rt<<1|1]);
}
node query(int L,int R,int l,int r,int rt){
if(L<=l&&R>=r)return A[rt];
int m=(l+r)>>1;
if(R<=m)return query(L,R,lson);
if(m<L)return query(L,R,rson);
node nl=query(L,m,lson),nr=query(m+1,R,rson);
return pushup(nl,nr);
}
int main(){
int n,m,c,i,a,b,p;
while(~scanf("%d%d%d",&n,&m,&c)){
for(i=1;i<=n;i++)scan_d(x[i]),x[i-1]=(x[i]-x[i-1])*50;
for(i=1;i<n;i++)scan_d(p),x[i]-=p*c;n--;
build(1,n,1);
ll ans=0,t;
while(m--){
scan_d(a),scan_d(b);
t=query(a,b-1,1,n,1).m;
if(t>0)ans+=t;
}
printf("%.8lf\n",ans*0.01);
}
return 0;
}