codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

355B.md (2443B)


      1 Source: https://codeforces.com/problemset/problem/355/B
      2 
      3 B. Vasya and Public Transport
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 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*.
     22 
     23 Public transport is not free. There are 4 types of tickets:
     24 
     25 1. A ticket for one ride on some bus or trolley. It costs *c*1 burles;
     26 2. A ticket for an unlimited number of rides on some bus or on some trolley. It costs *c*2 burles;
     27 3. A ticket for an unlimited number of rides on all buses or all trolleys. It costs *c*3 burles;
     28 4. A ticket for an unlimited number of rides on all buses and trolleys. It costs *c*4 burles.
     29 
     30 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.
     31 
     32 Input
     33 
     34 The first line contains four integers *c*1, *c*2, *c*3, *c*4 (1 ≤ *c*1, *c*2, *c*3, *c*4 ≤ 1000) — the costs of the tickets.
     35 
     36 The second line contains two integers *n* and *m* (1 ≤ *n*, *m* ≤ 1000) — the number of buses and trolleys Vasya is going to use.
     37 
     38 The third line contains *n* integers *a**i* (0 ≤ *a**i* ≤ 1000) — the number of times Vasya is going to use the bus number *i*.
     39 
     40 The fourth line contains *m* integers *b**i* (0 ≤ *b**i* ≤ 1000) — the number of times Vasya is going to use the trolley number *i*.
     41 
     42 Output
     43 
     44 Print a single number — the minimum sum of burles Vasya will have to spend on the tickets.
     45 
     46 Examples
     47 
     48 Input
     49 
     50 ```
     51 1 3 7 19  
     52 2 3  
     53 2 5  
     54 4 4 4
     55 ```
     56 
     57 Output
     58 
     59 ```
     60 12
     61 ```
     62 
     63 Input
     64 
     65 ```
     66 4 3 2 1  
     67 1 3  
     68 798  
     69 1 2 3
     70 ```
     71 
     72 Output
     73 
     74 ```
     75 1
     76 ```
     77 
     78 Input
     79 
     80 ```
     81 100 100 8 100  
     82 3 5  
     83 7 94 12  
     84 100 1 47 0 42
     85 ```
     86 
     87 Output
     88 
     89 ```
     90 16
     91 ```
     92 
     93 Note
     94 
     95 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.
     96 
     97 In the second sample the profitable strategy is to buy one ticket of the fourth type.
     98 
     99 In the third sample the profitable strategy is to buy two tickets of the third type: for all buses and for all trolleys.