PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#QHD0000093. Lịch dự tiệc (PARTY)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Lịch dự tiệc (PARTY)
PARTY
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
You are planning which of parties to attend. Party has entrance fee and provides fun . Your budget is , and each party may be attended at most once. Your first objective is to maximize total fun within the budget. Among all selections with maximum fun, minimize total spending. You may choose no party.
Input
The first line contains and , followed by lines containing .
Output
Print two integers: minimum spending among optimal selections, and maximum fun.
Subtasks
The independent scoring groups have the following complete constraints:
- Subtask 1 (20%): , , , .
- Subtask 2 (30%): , , , .
- Subtask 3 (50%): , , , .
Examples
Input
50 10
12 3
15 8
16 9
16 6
10 2
21 9
18 4
12 4
17 8
18 9
Output
49 26
Explanation
The maximum achievable fun is at a total fee of . No cheaper selection reaches fun , so output .