|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|1 초||128 MB||0||0||0||0.000%|
In the two-player game CosmoCraft you manage an economy in the hopes of producing an army capable of defeating your opponent. You manage the construction of workers, production facilities, and army units; the game revolves around balancing the resources you allocate to each. The game progresses in turns.
You start off with n workers and k production facilities. The game progresses in turns – at each turn, you can spend the income you get from your workers on a mixture of workers, army, and creating production facilities. Workers produced this round do not give you income until the next round; likewise, production facilities do not become active until the next round. Any unspent income from the current round carries over to the next.
At the end of a round, you can take the total army you’ve produced and attack your opponent; if you have strictly more units than your opponent, the opponent loses immediately, and you retain the difference of the army sizes. Otherwise, your army is crushed and your opponent is left with the difference of the army sizes. (it would be wise for him to counter-attack after this, but you don’t lose immediately at least). The game ends after t turns, at which point both players will usually attack with the larger army reigning victorious.
You’re playing against your friend, and since you’ve played against him so many times you know exactly what he’s going to spend his money on at every turn, and exactly when he’s going to attack. Knowing this, you’ve decided that the best strategy is to play defensively – you just want to survive every attack, and amass as large an army in the meantime so you can counterattack (and hopefully win) at the end of the game.
What’s the largest army you can have at the end of the game, given that you must survive all your friend’s attacks?
There will be several test cases in the input. Each test case will begin with a line with three integers:
n k t
where n (1≤n≤100) is the number of workers you start with, k (1≤k≤100) is the number of production facilities you have at the start, and t (1≤t≤10,000) is the number of turns. On the next line will be t-1 integers, ai (0≤ai≤Max signed 64-bit integer), separated by single spaces. The ith integer indicates the strength of the attack (that is, the number of army units your opponent is using in that attack) on turn i. The input will end with a line with three 0s.
For each test case output a single integer indicating the maximum number of armies you could have at the end of the game. Output -1 if it is impossible to survive. Output each integer on its own line, with no spaces, and do not print any blank lines between answers. While it is possible for some inputs to generate unreasonably large answers, all judge inputs yield answers which will fit in a signed 64-bit integer.
8 4 6 22 6 10 14 0 4 3 3 0 0 6 9 7 0 0 11 0 7 0 0 0 0
-1 11 101