Working in Beijing
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)Total Submission(s): 1939 Accepted Submission(s): 841
Problem Description
Mr. M is an undergraduate student of FDU. He finds an intern position in Beijing, so that he cannot attend all the college activities. But in some conditions, he must come back to Shanghai on certain date. We can assume the important activities that Mr. M must attend are occupy a whole day. Mr. M must take flight to Shanghai before that day and leave after that day. On the other hand, Mr. M is absent in Beijing and he will lose his salary for his absent.
Sometimes the cost of flight is much higher than the loss of salary, so to save the cost on the travel, Mr. M can stay in Shanghai to wait for another important date before he back to Beijing.
Now, Mr. M knows all of the important date in the next year. Help him schedule his travel to optimize the cost.
Sometimes the cost of flight is much higher than the loss of salary, so to save the cost on the travel, Mr. M can stay in Shanghai to wait for another important date before he back to Beijing.
Now, Mr. M knows all of the important date in the next year. Help him schedule his travel to optimize the cost.
Input
The input contains several test cases. The first line of single integer indicates the number of test cases.
For each test case, the first line contains three integers: n, a and b, denoting the number of important events, the cost of a single flight from Beijing to Shanghai or Shanghai to Beijing and the salary for a single day stay in Beijing. (1 <= n <= 100000, 1 <= a <= 1000000000, 1 <= b <=100)
Next line contains n integers ti, denoting the time of the important events. You can assume the ti are in increasing order and they are different from each other. (0 <= ti <= 10000000)
For each test case, the first line contains three integers: n, a and b, denoting the number of important events, the cost of a single flight from Beijing to Shanghai or Shanghai to Beijing and the salary for a single day stay in Beijing. (1 <= n <= 100000, 1 <= a <= 1000000000, 1 <= b <=100)
Next line contains n integers ti, denoting the time of the important events. You can assume the ti are in increasing order and they are different from each other. (0 <= ti <= 10000000)
Output
For each test case, output a single integer indicating the minimum cost for this year.
Sample Input
2 1 10 10 5 5 10 2 5 10 15 65 70
Sample Output
Case #1: 30 Case #2: 74
Source
Recommend
lcy
题意:
某人在北京要去上海开会,坐一次飞机要A的花费,待一天要B的花费。问最少的花费是多少。
思路:
判断一下是立马返回北京然后等到日期再飞回上海两次机票的花费高还是待到开会的花费高,然后择优选择。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn=100005;
ll d[maxn];
int main()
{
int t,n,a,b,cas=1;
scanf("%d",&t);
while(t--)
{
ll sum=0;
scanf("%d%d%d",&n,&a,&b);
for(int i=1;i<=n;i++)
{
scanf("%lld",&d[i]);
}
int f=0;
for(int i=1;i<=n;i++)
{
if(f==0)
{
sum+=(ll)a;
sum+=(ll)b;
f=1;
}
else
{
if(i!=1)
{
if((d[i]-d[i-1])*(ll)b>(ll)2*a+(ll)b)
{
f=0;
sum+=(ll)2*a;
}
else
{
sum+=(d[i]-d[i-1])*(ll)b;
}
}
}
if(i==n)
sum+=(ll)a;
}
printf("Case #%d: ",cas++);
printf("%lld\n",sum);
}
return 0;
}