#GD0000112. Đọc sách – phiên bản khó (Reading Books (hard version))
Bài tập thuộc lộ trình
Mục lục đề ⌄
Đọc sách – phiên bản khó (Reading Books (hard version))
Reading Books (hard version)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are books; book requires time, and bits indicate whether Alice and Bob like it. Choose exactly distinct books, with at least liked by Alice and at least liked by Bob, minimizing the total reading time. Print -1 if impossible, otherwise the minimum time and exactly indices.
Input
Line 1 contains . Each of the next lines contains .
Output
Print -1 if impossible. Otherwise line 1 contains the minimum time and line 2 contains exactly distinct indices from . Any optimum selection is accepted.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
6 3 1
6 0 0
11 1 0
9 0 1
21 1 1
10 1 0
8 0 1
Output
24
5 6 1
Explanation
Select books (time , liked by Bob), (time , liked by Alice), and (time ), totaling with exactly three books and each reader liking at least one. This is optimal.