Revizia anterioară Revizia următoare
Fişierul intrare/ieşire: | fairgame.in, fairgame.out | Sursă | IIOT 2019-20 Runda 3 |
Autor | Alexandru Petrescu | Adăugată de | |
Timp execuţie pe test | 0.2 sec | Limită de memorie | 256000 kbytes |
Scorul tău | N/A | Dificultate | N/A |
Vezi solutiile trimise | Statistici
Fairgame
Alice and Bob are playing a game. They have a pile of N rocks. Alice makes the first move, then Bob does the second, and so on... In each turn, the player that has to move takes at least 1 rock and maximum K rocks. If one takes an odd number of rocks, then they have to pay M dollars. When the pile is empty, the player who made the last move gets P dollars and the other one gets Q dollars. Knowing that they play optimally, which means Alice wants to maximize the difference in dollars between him and Bob wants to minimize this difference.
Date de intrare
On the first line of input in the file fairgame.in there are the values of N, K, M, P, Q in this order.
Date de ieşire
On the first line of the output file fairgame.out the value of the difference in dollars between Alice and Bob should be written
Restricţii
- 1 ≤ N, K, M, P, Q ≤ 5 * 10^6
- Pentru 30 puncte, $N ≤ 4000
- Pentru alte 10 puncte, N ≤ 10000, K ≤ 900
- Pentru alte 20 puncte, N ≤ 10000
Exemplu
fairgame.in | fairgame.out |
---|---|
6 3 5 4 2 | 2 |
Explicaţie
...