B. Vasya and Public Transport
2013-10-23 22:18
141 查看
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Vasya often uses public transport. The transport in the city is of two types: trolleys and buses. The city has
n buses and m trolleys, the buses are numbered by integers from
1 to n, the trolleys are numbered by integers from
1 to m.
Public transport is not free. There are 4 types of tickets:
A ticket for one ride on some bus or trolley. It costs
c1 burles;
A ticket for an unlimited number of rides on some bus or on some trolley. It costs
c2 burles;
A ticket for an unlimited number of rides on all buses or all trolleys. It costs
c3 burles;
A ticket for an unlimited number of rides on all buses and trolleys. It costs
c4 burles.
Vasya knows for sure the number of rides he is going to make and the transport he is going to use. He asked you for help to find the minimum sum of burles he will have to spend on the tickets.
Input
The first line contains four integers c1, c2, c3, c4
(1 ≤ c1, c2, c3, c4 ≤ 1000) — the costs of the tickets.
The second line contains two integers n and
m (1 ≤ n, m ≤ 1000) — the number of buses and trolleys Vasya is going to use.
The third line contains n integers
ai
(0 ≤ ai ≤ 1000) — the number of times Vasya is going to use the bus number
i.
The fourth line contains m integers
bi
(0 ≤ bi ≤ 1000) — the number of times Vasya is going to use the trolley number
i.
Output
Print a single number — the minimum sum of burles Vasya will have to spend on the tickets.
Sample test(s)
Input
Output
Input
Output
Input
Output
Note
In the first sample the profitable strategy is to buy two tickets of the first type (for the first bus), one ticket of the second type (for the second bus) and one ticket of the third type (for all trolleys). It totals to
(2·1) + 3 + 7 = 12 burles.
In the second sample the profitable strategy is to buy one ticket of the fourth type.
In the third sample the profitable strategy is to buy two tickets of the third type: for all buses and for all trolleys.
思路,经过分析能看出,三种类型的票实际是一种包含关系,因而可以按照3种票的关系分层处理,将问题转换为一个层层包含的树状结构,代码中dep指得就是层
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Vasya often uses public transport. The transport in the city is of two types: trolleys and buses. The city has
n buses and m trolleys, the buses are numbered by integers from
1 to n, the trolleys are numbered by integers from
1 to m.
Public transport is not free. There are 4 types of tickets:
A ticket for one ride on some bus or trolley. It costs
c1 burles;
A ticket for an unlimited number of rides on some bus or on some trolley. It costs
c2 burles;
A ticket for an unlimited number of rides on all buses or all trolleys. It costs
c3 burles;
A ticket for an unlimited number of rides on all buses and trolleys. It costs
c4 burles.
Vasya knows for sure the number of rides he is going to make and the transport he is going to use. He asked you for help to find the minimum sum of burles he will have to spend on the tickets.
Input
The first line contains four integers c1, c2, c3, c4
(1 ≤ c1, c2, c3, c4 ≤ 1000) — the costs of the tickets.
The second line contains two integers n and
m (1 ≤ n, m ≤ 1000) — the number of buses and trolleys Vasya is going to use.
The third line contains n integers
ai
(0 ≤ ai ≤ 1000) — the number of times Vasya is going to use the bus number
i.
The fourth line contains m integers
bi
(0 ≤ bi ≤ 1000) — the number of times Vasya is going to use the trolley number
i.
Output
Print a single number — the minimum sum of burles Vasya will have to spend on the tickets.
Sample test(s)
Input
1 3 7 19 2 3 2 5 4 4 4
Output
12
Input
4 3 2 1 1 3 798 1 2 3
Output
1
Input
100 100 8 100
3 5
7 94 12100 1 47 0 42
Output
16
Note
In the first sample the profitable strategy is to buy two tickets of the first type (for the first bus), one ticket of the second type (for the second bus) and one ticket of the third type (for all trolleys). It totals to
(2·1) + 3 + 7 = 12 burles.
In the second sample the profitable strategy is to buy one ticket of the fourth type.
In the third sample the profitable strategy is to buy two tickets of the third type: for all buses and for all trolleys.
思路,经过分析能看出,三种类型的票实际是一种包含关系,因而可以按照3种票的关系分层处理,将问题转换为一个层层包含的树状结构,代码中dep指得就是层
#include <iostream> using namespace std; int cost[4]; /*cost of four types*/ int dep1_a[10010]; int dep1_b[10010]; int dep2_a = 0; int dep2_b = 0; int dep3; int a[10010]; int b[10010]; int n,m; int main() { int i; for(i = 0 ; i < 4; i++){ cin >> cost[i]; } cin >> n >> m; for(i = 0; i < n; i++){ cin >> a[i]; } for(i = 0; i < m; i++){ cin >> b[i]; } /*dep1 check*/ for(int i = 0; i < n; i++){ dep1_a[i] = cost[1] < cost[0]*a[i] ? cost[1] : cost[0]*a[i]; dep2_a += dep1_a[i]; } for(int i = 0; i < m; i++){ dep1_b[i] = cost[1] < cost[0]*b[i] ? cost[1] : cost[0]*b[i]; dep2_b += dep1_b[i]; } /*dep2 check*/ if(cost[2] < dep2_a) dep2_a = cost[2]; if(cost[2] < dep2_b) dep2_b = cost[2]; dep3 = dep2_a + dep2_b; /*dep3 check*/ if(cost[3] < dep3) dep3 = cost[3]; cout << dep3 << "\n"; return 0; }
相关文章推荐
- Codeforces_355B_Vasya and Public Transport(贪心)
- Vasya and Public Transport
- B. Vasya and Public Transport
- codeforces B. Vasya and Public Transport 解题报告
- Codeforces Round #206 (Div. 2) B. Vasya and Public Transport
- cf B. Vasya and Public Transport
- ZCMU-1309-Vasya and Public Transport
- WCF 4 Step By Step Chapter 4 Note (Transport and Message Security + Authentication in Organization)
- cf #345 div2 C(Vasya and String。双端队列)
- Vasya and the Bus
- Link-based and Probe-based public network
- Codeforces Round #354 (Div. 2)——C. Vasya and String(尺取)
- 数学 之 Codeforces 354A - Vasya and Robot
- 关于make sure class name exists, is public, and has an empty constructor that is public解决办法
- Ipsec transport mode and turnnel mode
- D. Vasya and Chess
- Host Controller transport layer and AMPs
- [CF676C]Vasya and String(尺取法,原题)
- Codeforces Round #354 (Div. 2) C. Vasya and String
- White spaces are required between publicId and systemId.异常