#BS0000451. Cuộc chiến chống Mammoth (Against Mammoths)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Cuộc chiến chống Mammoth (Against Mammoths)
Against Mammoths
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
In a fictional interplanetary war, humans control planets and their opponents control . Human planet starts with spaceships and produces more each year. Opponent planet starts with mammoths and produces more annually. At the start of year , starting with year 0, a planet has its initial force plus times its annual production.
Assign exactly one human planet to each opponent planet. Each human planet may attack at most one opponent planet. If planet launches at the beginning of year , all its ships arrive at planet at the start of year . Mammoths continue to be produced during the journey. The attack succeeds when the number of ships is at least the number of mammoths upon arrival. Different planets may launch in different years.
Find the earliest year by which every opponent planet can be defeated, or report that it is impossible.
Input
The first line contains . The second contains integers . The third contains integers . The following lines each contain integers .
Output
Print the earliest year as an integer, or IMPOSSIBLE if no assignment works.
Subtasks
- Subtask 1 (20 points): , , , , .
- Subtask 2 (30 points): , , , , .
- Subtask 3 (50 points): , , , , .
Examples
Input 1
2 1
2 3 0 3
2 2
2
2
Output 1
6
Explanation 1
Planet 1 leaves in year 4 with 14 ships and arrives in year 6 to face 14 mammoths. Neither human planet can win before year 6.