codeforces 150C Smart Cheater

C. Smart Cheater
time limit per test
5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 [AC] and [DB], 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.

Input

The first line contains three integers nm and c (2 ≤ n ≤ 1.5·1051 ≤ m ≤ 3·1051 ≤ c ≤ 104).

The next line contains n integers xi (0 ≤ xi ≤ 109x1 = 0xi < 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.

Output

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.

Sample test(s)
input
3 3 10
0 10 100
100 0
1 2
2 3
1 3
output
90.000000000
input
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
output
76859.990000000
Note

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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值