#P17024. [ROI 2026 Day2] 火星背包

[ROI 2026 Day2] 火星背包

Background

Since the testdata for this problem is much larger than 4 GB and exceeds Luogu’s judging limit, some test points in Subtask 9 were removed. Please judge at https://www.luogu.com.cn/problem/U697179.

Because the testdata is large, the judge may need 2–4 minutes to load the testdata. This problem cannot provide testdata downloads. You may also test your solution at the link above first, and then submit to this problem to reduce waiting time.

Problem Description

The Martian Marvin is organizing his knapsack. In front of him there are nn items, numbered from 11 to nn. Each item has two attributes: item ii has weirdness wiw_i and value cic_i. Weirdness is a non-negative integer whose binary representation has at most kk bits (0≤wi<2k0 \le w_i < 2^k). Value is a non-negative integer not exceeding 10910^9 (0≤ci≤1090 \le c_i \le 10^9).

The total value of a set of items is the sum of the values of all items in it, and the total weirdness is defined as the bitwise OR of the weirdness values of all items in it.

Marvin calls a set of items valuable if and only if its total value is at least CC. For each ii (1≤i≤n1 \le i \le n), Marvin wants to choose a valuable subset from the items with indices at most ii, so that the subset’s total weirdness is as small as possible.

The bitwise OR of a set of integers is defined as follows: consider the binary representations of these numbers. The ii-th bit of the result is 11 if and only if at least one of these numbers has its ii-th bit equal to 11. In programming languages, this operation is denoted by the symbol ∣\mid. For example, $(10 \mid 3 \mid 9) = (1010_2 \mid 0011_2 \mid 1001_2) = 1011_2 = 11$.

Input Format

The first line contains three integers nn, kk, CC (1≤n≤2 000 0001 \le n \le 2\,000\,000, 1≤k≤221 \le k \le 22, 1≤C≤10151 \le C \le 10^{15}), representing the number of items, the upper limit on the number of bits in weirdness, and the minimum total value for a valuable subset.

The next nn lines each contain two integers wiw_i and cic_i (0≤wi<2k0 \le w_i < 2^k, 0≤ci≤1090 \le c_i \le 10^9), representing the weirdness and value of item ii.

Output Format

Output nn numbers. The ii-th number should be the minimum total weirdness among valuable subsets chosen from the first ii items. If it is impossible to choose such a subset, output −1-1.

5 4 12
8 7
2 6
3 6
1 12
3 5
-1
10
3
1
1

Hint

Explanation

For i=1i = 1, there is only one item with weirdness 88 and value 77. Since it is impossible to choose a subset whose total value is at least 1212, the answer is −1-1.

For i=2i = 2, there are two items. The only valuable choice is to take both items, and the total weirdness is 8∣2=108 \mid 2 = 10.

For i=3i = 3, any subset containing at least two items is valuable. The best plan is to choose item 22 and item 33, and the total weirdness is 2∣3=32 \mid 3 = 3.

For i=4i = 4, you can take only the fourth item, since its value is already enough. Its weirdness is 11, which is the smallest possible value. For i=5i = 5, taking only the fourth item is also optimal.

Subtasks

Subtask Score nn kk Additional Constraints Dependencies
1 10 n≤20n \le 20 k≤10k \le 10 --
2 11 n≤100n \le 100 1
3 14 n≤50 000n \le 50\,000 1–2
4 13 n≤1 000 000n \le 1\,000\,000 k≤19k \le 19 All wiw_i are powers of 22 --
5 11 n≤2 000n \le 2\,000 -- -- 1–2
6 18 n≤500 000n \le 500\,000 k≤16k \le 16 1–3
7 6 n≤1 000 000n \le 1\,000\,000 k≤19k \le 19 1–4, 6
8 -- 1–4, 6–7
9 11 -- 1–8

Translated by DeepSeek V4 Pro.

Translated by ChatGPT 5