PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000114. Đọc sách – phiên bản dễ (Reading Books (easy version))
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đọc sách – phiên bản dễ (Reading Books (easy version))
Reading Books (easy version)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Among books, book takes time and is liked by Alice if , by Bob if . Alice and Bob read the same arbitrary subset of books. Each must like at least chosen books. Minimize the total reading time or print -1 if impossible.
Input
Line 1 contains . The next lines contain .
Output
Print the minimum total reading time or -1 if impossible.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
5 2
6 0 0
9 0 0
1 0 1
2 1 1
5 1 0
Output
8
Explanation
Choose books , , of times . Alice likes books , Bob likes ; the total time is , which is optimal.