print870. 18,000 Seconds Remaining

print18,000 Seconds Remaining

Ограничения: время – 1s/2s, память – 32MiB Ввод: input.txt или стандартный ввод Вывод: output.txt или стандартный вывод copy
Послать решение Blockly Посылки Темы Где Обсудить (0)

A feature of many file transfer programs is the ability to estimate the amount of time remaining in the transfer. These programs estimate the time remaining based on the number of bytes left to be transferred and the rate of transfer in previous seconds. You are to write a program to simulate this behavior.
The input will be a series of data sets, each set describing one file transfer. The first line of each data set will be a single non-negative integer, telling the size of the file in bytes. The subsequent lines will be the number of bytes transmitted in each second (all non-negative integers). The sum of the bytes transmitted will equal the number of bytes in the file.
The end of input will be indicated by a file size of 0 bytes. This data set should not be processed.
The output for each data set should begin with a line with the number of the data set and the size of the file being transferred. Then, there should be update lines estimating how many seconds remain, issued once every 5 seconds during the transfer.
To estimate the number of seconds remaining, first determine the transfer rate (bytes/second) for the previous 5 seconds. If no bytes were transferred during this time, then the transfer is stalled, and your program should report this. Otherwise, divide the number of bytes remaining to be transferred by the transfer rate for the previous 5 seconds to estimate the number of seconds remaining.
Report the number of seconds remaining as an integer. Always round up in reporting how much time is remaining (so if there are 12.2 seconds remaining, you should report there are 13 seconds remaining).
At the end of the transfer, print a line telling how many seconds the transfer took. Use the format in the sample.
There should be one blank line after the output from each data set.

Sample Input

100
10
20
20
0
10
0
10
0
10
0
20
200
60
30
100
10
50
5
5
5
5
25
0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
0

Sample Output

Output for data set 1, 100 bytes:
   Time remaining: 4 seconds
   Time remaining: 5 seconds
Total time: 11 seconds
 
Output for data set 2, 200 bytes:
Total time: 4 seconds
 
Output for data set 3, 50 bytes:
   Time remaining: 1 seconds
   Time remaining: stalled
   Time remaining: stalled
   Time remaining: 0 seconds
Total time: 20 seconds

Source: unknown, uva 362
loading