beecrowd | 1369

Memory Manager

By Paulo Oliva Brazil

Timelimit: 3

It’s true that most of people don’t care about what happens inside a computer, since it execute the tasks correctly. There are, however, a couple few nerds that feel good seeing the movement of bits and bytes inside the computer memory.

It’s for this audience, composed mostly by teenagers, that the software multinational ACM (Abstractions of Concrete Machines) wants to develop a system that follow and produce a report of the operations in a hard disk. A hard disk is composed of a sequence of storage atomic cells, each one of 1Kb size.

Specifically, ACM wants to follow three kinds of operations:

Inserts the file NAME on the disk, of size T. You may assume that a file with such name doesn’t exist on the disk. The size T from a file is given in the form XKb, XMb, XGb, where X is an integer (0 < X <= 1023). NAME is a character array with maximum length 10.

Remove the file NAME from the disk. If a file with such name doesn’t exist, it does nothing.

Compact the disk, shifting existent files to the beginning of the disk, removing free spaces between two subsequent two files, and preserving the order in that the files show in the disk, in a way that leaves free memory at the end of the disk.

The disk storage capacity is always a multiple of 8Kb. At the beginning, the disk is empty, in other words, has a free block of the size of the disk capacity. A file is always stored in a cell block of contiguous storage. The file to be inserted must always be inserted at the beginning of the smaller free block such size is bigger or equal the file’s size. If more than one free block are equally appropriate, choose the closest to the beginning of the disk. Whether it’s not possible to insert the file by lack of a free big enough block, it must automatically execute the otimiza operation.  If after the optimization it still not possible to inset the file, an error message must be produced. If all the operations were executed without errors, your program must produce one approximated estimative of the disk final stage, as described below.

Remember that 1Mb correspond to 1024Kb, while 1Gb correspond to 1024Mb.


The input is composed by several test cases. The first line of a test case contains only one integer N indicating the number of operations in the disk (0 < N ≤ 10000). The second line of a test case contains the description of the disk size, composed by an integer D (0 < D ≤ 1023), followed by a unity specification; the unity specification is a character array of two characters in the format Kb, Mb or Gb. Each one of the next N lines contains a description of one disk operation (insere, remove or otimiza, as described above). The end of the input is indicated by = 0.


To each test case your program must produce one output line. If all the insert operations were executed without errors, your program must produce one line containing an approximated estimative of the disk stage, as follows. Divide the number of the disk bytes in eight contiguous blocks of the same size. To each one of the eight blocks your program must verify the percentage P of free bytes in that block, and show the estimate of the final stage at the format

[C] [C] [C] [C] [C] [C] [C] [C]

where C is ' ', '-' or '#', depend if 75 < P ≤ 100, 25 < P ≤ 75 or 0 ≤ P ≤ 25, respectively. Whether a file can’t be inserted by lack of memory, your program must produce one line containing the expression ERRO: disco cheio; in such case, subsequent operations of the test case must be ignored.

Sample Input Sample Output

insere arq0001 7Kb
insere arq0002 3Mb
remove arq0001
insere arq0001 4Mb
insere arq0002 1Mb
insere arq0003 512Kb
remove arq0001
remove arq0001
insere arq0001 5Mb

ERRO: disco cheio
[#] [#] [#] [#] [#] [#] [-] [ ]