eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Dreadful Deadlines

Dreadful Deadlines

Contrary to popular belief, diligence does not always pay off! Over the course of his years as an earnest Stanford undergraduate, David found that despite his best efforts, work would always expand to fill the time available. In order to improve his day-to-day efficiency, David has decided to learn the art of procrastination. David has \textbf{n} assignments due next week. The \textbf{i}th assignment takes \textbf{x_i} units of time and must be finished by time \textbf{t_i}. David can only work on one assignment at a time, and once David begins an assignment, he must work until it is finished. What is the latest time that David can start in order to ensure that all his deadlines are met? \textbf{Input} The input file will contain multiple test cases. Each test case consists of three lines. The first line of each test case contains a single integer \textbf{n} (\textbf{1} ≤ \textbf{n} ≤ \textbf{1000}). The second line of each test case contains \textbf{n} integers, \textbf{x_1} \textbf{x_2} ... \textbf{x_n} (\textbf{1} ≤ \textbf{x_i} ≤ \textbf{10}) separated by single spaces. The third line of each test case contains \textbf{n} integers, \textbf{t_1} \textbf{t_2} ... \textbf{t_n} (\textbf{1} ≤ \textbf{t_i} ≤ \textbf{1000}) separated by single spaces. A blank line separates input test cases, as seen in the sample input below. A single line containing "\textbf{0}" marks the end of input; do not process this case. \textbf{Output} For each input test case, print a single line containing an integer indicating the latest time that Jim can start yet still manage to finish all his assignments on time. If the latest time would require Jim to start before time \textbf{0}, print "\textbf{impossible}".
Лимит времени 0.3 секунд
Лимит использования памяти 64 MiB
Входные данные #1
3
1 2 1
9 9 7

2
2 2
3 3

0
Выходные данные #1
5
impossible