[Solution] Lemper Cooking Competition Codeforces Solution
Pak Chanek is participating in a lemper cooking competition. In the competition, Pak Chanek has to cook lempers with stoves that are arranged sequentially from stove to stove . Initially, stove has a temperature of degrees. A stove can have a negative temperature.
Pak Chanek realises that, in order for his lempers to be cooked, he needs to keep the temperature of each stove at a non-negative value. To make it happen, Pak Chanek can do zero or more operations. In one operation, Pak Chanek chooses one stove with , then:
- changes the temperature of stove into ,
- changes the temperature of stove into , and
- changes the temperature of stove into .
Pak Chanek wants to know the minimum number of operations he needs to do such that the temperatures of all stoves are at non-negative values. Help Pak Chanek by telling him the minimum number of operations needed or by reporting if it is not possible to do.
The first line contains a single integer () — the number of stoves.
The second line contains integers () — the initial temperatures of the stoves.
Output an integer representing the minimum number of operations needed to make the temperatures of all stoves at non-negative values or output if it is not possible.
For the first example, a sequence of operations that can be done is as follows:
- Pak Chanek does an operation to stove , .
- Pak Chanek does an operation to stove , .
- Pak Chanek does an operation to stove , .
- Pak Chanek does an operation to stove , .
There is no other sequence of operations such that the number of operations needed is fewer than .
No comments:
Post a Comment