PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000065. Tối thiểu tổng phiếu bầu (AtCoDeer and Election Report)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tối thiểu tổng phiếu bầu (AtCoDeer and Election Report)
AtCoDeer and Election Report
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Two election candidates receive votes over time; neither candidates vote count can ever decrease. AtCoder observes N reports in chronological order. Report i specifies the current ratio T_i:A_i of their positive vote counts, but not their actual counts. Find the minimum possible sum of the two vote counts at the final observation that is consistent with all reports.
Input
First line: N. The next N lines each contain T_i A_i.
Output
The minimum possible sum of votes at the last observation.
Subtasks
- Subtask 1 (20 points): , , , answer .
- Subtask 2 (30 points): , , , answer .
- Subtask 3 (50 points): , , , answer .
Examples
Input
3
2 3
1 1
3 2
Output
10
Explanation
The sequence of vote counts (2,3), (3,3), (6,4) respects all ratios, never decreases either count, and finishes at total 10.