#GD0000020. Bộ chứng minh tham lam (Greedy Proof Set)
Bộ chứng minh tham lam (Greedy Proof Set)
Greedy Proof Set
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
The input contains four independent greedy exercises. (A) Choose exactly smallest prices and print their sum. (B) Choose the minimum number of capacities whose sum reaches at least . (C) Represent amount using denominations with the fewest notes. (D) Delete exactly one bit from a binary string with no leading zero to maximize the remaining value. Print the four answers in order.
Input
Part A: one line , then one line with prices. Part B: one line , then one line with capacities, whose total is guaranteed to reach . Part C: one line with . Part D: one line with binary string .
Output
Print four lines: the minimum sum for A; the minimum count for B; the minimum note count for C; and the maximum binary string for D.
Subtasks
General constraints:
-
.
-
.
-
, .
-
, .
-
.
-
.
-
Subtask 1 (20 points): ,
-
Subtask 2 (30 points): ,
-
Subtask 3 (50 points): No additional constraints.
Examples
Input
5 3
8 2 5 1 4
4 10
6 4 3 2
43
110010
Output
7
2
5
11010
Explanation
A: . B: the two largest capacities , so the answer is . C: , requiring notes. D: deleting the first 0 gives 11010.