F
F
Frontend1232021-01-20 21:42:40
Node.js
Frontend123, 2021-01-20 21:42:40

How to solve such problems? on node js, with input and output data?

The company your friend still works for has decided to install tea and coffee vending machines in their minibuses so that passengers can have a good time during trips and especially while waiting in traffic jams.

The cost of a glass of tea and coffee in the machine is supposed to be set equal to five rubles. The machines will accept coins of 5 and 10 rubles, as well as banknotes of 10, 50 and 100 rubles. When a passenger needs to give change (that is, when a passenger has thrown a ten-ruble coin or a 10-, 50- or 100-ruble bill into the machine), the machine gives change in five-ruble coins; if a passenger throws a five-ruble coin into the machine, then the machine saves it and can use it for change to the next passengers.

It is clear that in order to provide the possibility of issuing change to all customers, it may be necessary to initially load a certain amount of five-ruble coins into the machine. Now, firms are undergoing tests on minibuses in order to determine the minimum number of coins that must be loaded into the machine before the minibus leaves for a flight. You are given a protocol of one of these tests: you know the order in which passengers paid for their purchases with various coins and banknotes. Determine the minimum number of five-ruble coins that should have been in the vending machine initially so that all passengers have enough change.

Input data
The first line of the input file contains one natural number — the number of purchases in the machine that were made during the test (1≤≤50000). The second line contains natural numbers, each of which is equal to the face value of the coin or banknote that the next buyer used to pay; each denomination can take one of four values: 5, 10, 50, or 100.

Output
In the output file, print a single number — the minimum number of five-ruble coins that had to be loaded into the machine initially so that all customers had enough change.

Note
In the first example, one five-ruble coin will be required for change to the first buyer and 19 coins to the third, but when changing to the third, it will be possible to use the coin that the second buyer throws, so initially 19 coins are enough in the machine.

In the second example, change can be given to a third customer using either the first or second customer's coin, and therefore it is not necessary to load the coins into the machine initially.

In the third example, the first customer needs nine coins of change, and all of them must initially be in the machine.

Examples
input
3
10 5 100

output
19

input
3
5 5 10

output
0

input
4
50 5 5 5

output
9

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
t800zippygod, 2021-01-20
@t800zippygod

1) Read from the input stream (process.stdin) and parse this input (split into rows, columns, etc., depending on the task condition, where what data is)
2) Perform calculations and receive an answer
3) Issue a response to the output stream (process .stdout)
Read the documentation about the nuances of working with streams.
PS If you need to work with files, then it's more convenient to use fs.readFile, fs.writeFile, more details in the documentation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question