HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Data Structures > problem:


50794 - Writing Files Into HDD

Guest
• Review clarifications (2)

Volume problems

• 50772 - The Path of a Node
• 50936 - Saving the Soldiers
• 51086 - Top popular student
• 51015 - Student Scholarships
• 50828 - Arranging Time Table
• 50447 - Swimming Contest - 2
• 51072 - Castle on chessboard
• 51082 - Sum is equal to K - 1
• 50794 - Writing Files Into HDD
• 51020 - Number of nodes removed
• 51023 - Preparing Keyword Index
• 50929 - Present from your uncles
• 51075 - Shortest Path for Bishop
• 50863 - Total Access Cost of a BST
• 50979 - Minimum access cost for BST
• 50688 - Epoka Furgon
• 50750 - Service Time - 2

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 2500/25000/65000/65000 Kb.
Question by Ibrahim Mesecan.

Writing Files Into HDD

For your National Science Academy, you are working on a new operating system. You want to prepare an algorithm to save the files. You know the positions and size of empty locations. You start with the biggest file and it is written to the biggest empty block. After writing the file to an empty block, the size of empty block is reduced according to the size of current file (sizeofEmptyBlock-=currentFileSize). If the biggest empty block is smaller than the current file size, then the current file continues from the next biggest empty block.

Question:Write a program that is going to read the sizes of n files and sizes of empty locations. In the end, your program should calculate and show the size of the biggest empty block.

Input specification
In the beginning, you will be given two integers: (n) the number of files and (m) the number of empty blocks. The next several lines will have the sizes of n files (separated by spaces and there are at most 25 numbers in every line). And the next several lines contain the size of m blocks where 0 ≤ (n and m) ≤ 50000 and the file sizes are between 0 and 1000000. The size of empty blocks are between 1 and 1000000000.

Output specification
Show one integer number: size of the biggest empty block.

Sample Input I
4 3
18 8 9 11
25 15 16
Sample Input II
4 4
4 3 9 9
5 8 5 12
Sample Output I
5
Sample Output II
3


Для отправки решений необходимо выполнить вход.

www.contester.ru