HDU5477 A Sweet Journey

来源:互联网 发布:淘宝小野妹子是正品吗 编辑:程序博客网 时间:2024/06/05 10:02

Description

Master Di plans to take his girlfriend for a travel by bike. Their journey, which can be seen as a line segment of length L, is a road of swamps and flats. In the swamp, it takes A point strengths per meter for Master Di to ride; In the flats, Master Di will regain B point strengths per meter when riding. Master Di wonders:In the beginning, he needs to prepare how much minimum strengths. (Except riding all the time,Master Di has no other choice) 

Input

In the first line there is an integer t (), indicating the number of test cases. 
For each test case: 
The first line contains four integers, n, A, B, L. 
Next n lines, each line contains two integers: , which represents the interval  is swamp. 

Make sure intervals are not overlapped which means  for each i (). 
Others are all flats except the swamps. 

Output

For each text case: 
Please output “Case #k: answer”(without quotes) one line, where k means the case number counting from 1, and the answer is his minimum strengths in the beginning. 

Sample Input

12 2 2 51 23 4

Sample Output

Case #1: 0

如果把这个看成赚钱和还钱的话,骑在平地上是赚了,骑在沼泽是亏了,开始本金是0,然后就找在骑得过程中最多亏多少,那就是我们要找的最小的所需要的体力。

#include <stdio.h>int main(){int t,icase;scanf("%d",&t);for(icase=1;icase<=t;icase++){int n,A,B,L;int i,j,k;scanf("%d%d%d%d",&n,&A,&B,&L);int min=0,power=0;int point=0;for(i=0;i<n;i++){int r,l;scanf("%d%d",&r,&l);power-=(r-point)*B;power+=(l-r)*A;if(power>min)min=power;point=l;}printf("Case #%d: %d\n",icase,min);}return 0;}

1 0