codeforces-scrape

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

734C.md (3661B)


      1 Source: https://codeforces.com/problemset/problem/734/C
      2 
      3 C. Anton and Making Potions
      4 
      5 time limit per test
      6 
      7 4 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Anton is playing a very interesting computer game, but now he is stuck at one of the levels. To pass to the next level he has to prepare *n* potions.
     22 
     23 Anton has a special kettle, that can prepare one potions in *x* seconds. Also, he knows spells of two types that can faster the process of preparing potions.
     24 
     25 1. Spells of this type speed up the preparation time of one potion. There are *m* spells of this type, the *i*-th of them costs *b**i* manapoints and changes the preparation time of each potion to *a**i* instead of *x*.
     26 2. Spells of this type immediately prepare some number of potions. There are *k* such spells, the *i*-th of them costs *d**i* manapoints and instantly create *c**i* potions.
     27 
     28 Anton can use no more than one spell of the first type and no more than one spell of the second type, and the total number of manapoints spent should not exceed *s*. Consider that all spells are used instantly and right before Anton starts to prepare potions.
     29 
     30 Anton wants to get to the next level as fast as possible, so he is interested in the minimum number of time he needs to spent in order to prepare at least *n* potions.
     31 
     32 Input
     33 
     34 The first line of the input contains three integers *n*, *m*, *k* (1 ≤ *n* ≤ 2·109, 1 ≤ *m*, *k* ≤ 2·105) — the number of potions, Anton has to make, the number of spells of the first type and the number of spells of the second type.
     35 
     36 The second line of the input contains two integers *x* and *s* (2 ≤ *x* ≤ 2·109, 1 ≤ *s* ≤ 2·109) — the initial number of seconds required to prepare one potion and the number of manapoints Anton can use.
     37 
     38 The third line contains *m* integers *a**i* (1 ≤ *a**i* < *x*) — the number of seconds it will take to prepare one potion if the *i*-th spell of the first type is used.
     39 
     40 The fourth line contains *m* integers *b**i* (1 ≤ *b**i* ≤ 2·109) — the number of manapoints to use the *i*-th spell of the first type.
     41 
     42 There are *k* integers *c**i* (1 ≤ *c**i* ≤ *n*) in the fifth line — the number of potions that will be immediately created if the *i*-th spell of the second type is used. It's guaranteed that *c**i* are not decreasing, i.e. *c**i* ≤ *c**j* if *i* < *j*.
     43 
     44 The sixth line contains *k* integers *d**i* (1 ≤ *d**i* ≤ 2·109) — the number of manapoints required to use the *i*-th spell of the second type. It's guaranteed that *d**i* are not decreasing, i.e. *d**i* ≤ *d**j* if *i* < *j*.
     45 
     46 Output
     47 
     48 Print one integer — the minimum time one has to spent in order to prepare *n* potions.
     49 
     50 Examples
     51 
     52 Input
     53 
     54 ```
     55 20 3 2  
     56 10 99  
     57 2 4 3  
     58 20 10 40  
     59 4 15  
     60 10 80
     61 ```
     62 
     63 Output
     64 
     65 ```
     66 20
     67 ```
     68 
     69 Input
     70 
     71 ```
     72 20 3 2  
     73 10 99  
     74 2 4 3  
     75 200 100 400  
     76 4 15  
     77 100 800
     78 ```
     79 
     80 Output
     81 
     82 ```
     83 200
     84 ```
     85 
     86 Note
     87 
     88 In the first sample, the optimum answer is to use the second spell of the first type that costs 10 manapoints. Thus, the preparation time of each potion changes to 4 seconds. Also, Anton should use the second spell of the second type to instantly prepare 15 potions spending 80 manapoints. The total number of manapoints used is 10 + 80 = 90, and the preparation time is 4·5 = 20 seconds (15 potions were prepared instantly, and the remaining 5 will take 4 seconds each).
     89 
     90 In the second sample, Anton can't use any of the spells, so he just prepares 20 potions, spending 10 seconds on each of them and the answer is 20·10 = 200.