#BS0000337. Mua vật phẩm giảm giá (bản khó) (Microtransactions (hard version))
Bài tập thuộc lộ trình
Mục lục đề ⌄
Mua vật phẩm giảm giá (bản khó) (Microtransactions (hard version))
Microtransactions (hard version)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are item types. An must purchase exactly units of type . Starting on day 1, An receives one coin each morning and saves unused coins. Each evening any number of items can be bought within the available money. The regular unit price is two coins. Offer makes type cost one coin per unit on day . Offers may coincide. Find the earliest day on which all required items can be purchased.
Input
First line: . Second line: integers . Each of the following lines contains .
Output
Print the minimum day.
Subtasks
- Subtask 1 (20 points): ; ; ; ; ; .
- Subtask 2 (30 points): ; ; ; ; ; all offers have the same day.
- Subtask 3 (50 points): ; ; ; ; .
Examples
Input 1
2 2
2 1
1 1
3 1
Output 1
4
Explanation
On day 3 buy two type-1 items for two coins. On day 4 buy the type-2 item for two coins. At least four coins are required.
Input 2
1 1
3
10 1
Output 2
6
Explanation
The offer comes too late; buying all three at regular price takes six days.