#GD0000020. Bộ chứng minh tham lam (Greedy Proof Set)

    ID: 1317 Loại: Thông thường 2000ms 256MiB Tried: 0 Đã chấp nhận: 0 Độ khó: 1 Đăng bởi: Nhãn>Greedy AlgorithmsGreedy proof techniquesExchange argumentsSorting and SearchingBasic mathematics

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 KK smallest prices and print their sum. (B) Choose the minimum number of capacities whose sum reaches at least TT. (C) Represent amount VV using denominations 1,5,10,20,1001,5,10,20,100 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 nA,Kn_A,K, then one line with nAn_A prices. Part B: one line nB,Tn_B,T, then one line with nBn_B capacities, whose total is guaranteed to reach TT. Part C: one line with VV. Part D: one line with binary string ss.

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:

  • 1≤K≤nA≤10001 \le K \le n_A \le 1000.

  • 1≤pi≤1061 \le p_i \le 10^6.

  • 1≤nB≤10001 \le n_B \le 1000, 1≤T≤1091 \le T \le 10^9.

  • 1≤bi≤1091 \le b_i \le 10^9, ∑bi≥T\sum b_i \ge T.

  • 1≤V≤1091 \le V \le 10^9.

  • 2≤∣s∣≤1052 \le |s| \le 10^5.

  • Subtask 1 (20 points): nA,nB≤20n_A,n_B \le 20, ∣s∣≤20|s| \le 20

  • Subtask 2 (30 points): nA,nB≤200n_A,n_B \le 200, ∣s∣≤5000|s| \le 5000

  • 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: 1+2+4=71+2+4=7. B: the two largest capacities 6+4=106+4=10, so the answer is 22. C: 43=20+20+1+1+143=20+20+1+1+1, requiring 55 notes. D: deleting the first 0 gives 11010.