#BS0000278. Nâng cấp lò bánh (Bakery)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Nâng cấp lò bánh (Bakery)
Bakery
Source: USACO
Version: Phuoc Hung OJ Extended
Problem Statement
Bessie has one oven. A cookie takes time units and a muffin takes . The oven processes only one pastry at once, and starts an order only when it is placed. N friends arrive separately; friend i orders cookies and muffins and can wait at most time units. Before their visits, each coin reduces either production time by one; both times must remain positive integers. Minimize the coins required to satisfy every order.
Input
First line: . Each of the following N lines contains .
Output
Print the minimum number of coins.
Subtasks
- Subtask 1 (20 points): ; ; ; ().
- Subtask 2 (30 points): ; ; ; ().
- Subtask 3 (50 points): ; ; ; ().
Examples
Input 1
3 7 9
4 3 18
2 4 19
1 1 6
Output 1
11
Explanation
Reduce the times to 3 and 2 for 11 coins; orders take 18,14,5. With only ten reductions the times sum to six; the first two orders cannot both be satisfied by positive times.