Codeforces Round #206 (Div. 2) B. Vasya and Public Transport

44 篇文章 0 订阅
B. Vasya and Public Transport
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:

  1. A ticket for one ride on some bus or trolley. It costs c1 burles;
  2. A ticket for an unlimited number of rides on some bus or on some trolley. It costs c2 burles;
  3. A ticket for an unlimited number of rides on all buses or all trolleys. It costs c3 burles;
  4. 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 12
100 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.

分成几类就好了!

#include <iostream>
#include <stdio.h>
using namespace std;
int pri[2000][4];
int main()
{
    int c[6],ans,n[6],s[6],i,j;
    while(scanf("%d%d%d%d",&c[1],&c[2],&c[3],&c[4])!=EOF){
        scanf("%d%d",&n[1],&n[2]);
        for(i=0;i<n[1];i++)
        scanf("%d",&pri[i][1]);
        for(i=0;i<n[2];i++)
        scanf("%d",&pri[i][2]);
        for(j=1,s[1]=s[2]=0;j<=2;j++)
        for(i=0;i<n[j];i++)
        {
            s[j]+=min(pri[i][j]*c[1],c[2]);
        }
        ans=min(s[1]+c[3],s[2]+c[3]);
        ans=min(s[1]+s[2],ans);
        ans=min(ans,2*c[3]);
        ans=min(ans,c[4]);
        printf("%d\n",ans);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值