QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 1024 MB Puntuación total: 100

#8368. T1

Estadísticas

Little T has $n$ items, where the $i$-th item has color $c_i$ and weight $a_i$.

Little T has $m$ backpacks. The $i$-th backpack must contain at least $l_i$ items and at most $r_i$ items, and all items in the $i$-th backpack must have color $i$.

The weight of a valid configuration is the sum of the weights of all items placed in the backpacks.

Find the weights of the $k$ smallest valid configurations. Two configurations are considered different if and only if there exists an item that is placed in a backpack in one configuration but not in the other.

Input

The first line contains three integers $n, m, k$, representing the number of items, the number of backpacks, and the number of smallest configurations to find.

The next $n$ lines each contain two integers $c_i, a_i$, representing the color and weight of the $i$-th item.

The next $m$ lines each contain two integers $l_i, r_i$, representing the lower and upper capacity limits of the backpacks.

Output

Output $k$ lines. The $i$-th line should contain an integer representing the $i$-th smallest weight. If the number of valid configurations is less than $i$, output $-1$.

Examples

Input 1

6 3 7
1 3
1 1
2 5
3 2
1 1
2 3
2 5
1 1
0 1

Output 1

5
7
7
7
7
8
9

Input 2

6 2 6
2 1
2 2
2 3
1 1
1 1
1 1
3 3
0 1

Output 2

3
4
5
6
-1
-1

Constraints

For all data, $1\leq n, m, k\leq 2\times 10^5$, $1\leq c_i\leq m$, $1\leq a_i\leq 10^9$, $0\leq l_i\leq r_i\leq n$.

Subtask 1 (15 points): $n, m, k\leq 4000$, $l_i=r_i=1$.

Subtask 2 (17 points): $n, m, a_i\leq 4000$, $l_i=r_i=1$.

Subtask 3 (25 points): $l_i=r_i=1$.

Subtask 4 (18 points): $l_i=0$.

Subtask 5 (25 points): No special restrictions.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.