PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#TP0000039. Ghép cặp bò (Paired Up)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Ghép cặp bò (Paired Up)
Paired Up
Source: USACO
Version: Phuoc Hung OJ Extended
Problem Statement
A farm has an even number of cows. They are described by groups: group contains cows, each with milk output . The values are pairwise distinct. All cows must be partitioned into pairs. Milking a pair takes time equal to the sum of its members’ milk outputs, and all pairs are milked simultaneously. Minimize the maximum pair time.
Input
- The first line contains , the number of groups.
- Each of the next lines contains and : the count and milk output of cows in that group. The total is even.
Output
Print one integer: the minimum time to finish milking all pairs.
Subtasks
- Subtask 1 (20 points): ; ; for all ; pairwise distinct; and even.
- Subtask 2 (30 points): ; ; for all ; pairwise distinct; and even.
- Subtask 3 (50 points): ; ; for all ; pairwise distinct; and even.
Examples
Input
3
1 8
2 5
1 2
Output
10
Explanation
The outputs are . Pair with (time ) and the two cows of output together (time ). Pairing output with output would take . As output must be paired with a cow of output at least , finishing in less than is impossible.