#FT0000057. Cập nhật điểm và hạn mức thẻ (Balance Update Query)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Cập nhật điểm và hạn mức thẻ (Balance Update Query)
Balance Update Query
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are kinds of cards. Kind has score per card and a selection quota of at most cards. Multiple cards of the same kind may be chosen, within its quota.
Process queries in order: 1 x y assigns score to kind ; 2 x y assigns quota to kind ; 3 x asks for the maximum possible total score when choosing exactly cards. If the sum of all quotas is smaller than , output -1. Assignments affect all subsequent queries.
Input
- Line 1: integer , number of card kinds.
- Next lines: each line contains score and quota .
- Next line: integer .
- Next lines: operations in the format
1 x y,2 x y, or3 x.
Output
For each type 3 query, print one integer: the maximum score or -1 if the requested number of cards cannot be selected.
Subtasks
Subtask 1 (20 points):
- ; , for each kind; type
1: ; type2: ; type3: ; at least one type3query occurs.
Subtask 2 (30 points):
- ; , for each kind; type
1: ; type2: ; type3: ; at least one type3query occurs.
Subtask 3 (50 points):
- ; , for each kind; type
1: ; type2: ; type3: ; at least one type3query occurs.
Examples
Examples 1
Input
3
1 1
2 2
3 3
7
3 4
1 1 10
3 4
2 1 0
2 3 0
3 4
3 2
Output
11
19
-1
4
Explanation
Initially, the best four cards score . After raising kind 1 to score 10, the best four score . Setting quotas of kinds 1 and 3 to zero leaves only two cards of kind 2, so choosing four is impossible. Choosing two cards scores .
Examples 2
Input
2
5 1
2 2
5
3 2
2 1 0
3 2
1 2 7
3 2
Output
7
4
14
Explanation
Initially, choose scores 5 and 2 to obtain 7. Setting kind 1 quota to zero leaves two cards of score 2, totaling 4. Updating kind 2 score to 7 makes the best pair total 14.
For the first 3 2 query, the total quota is , so selecting two cards is possible; the best scores are and . After 2 1 0, kind 1 cannot be selected and the total quota is just . Operation 1 2 7 changes a score, not a quota, so both final selected cards score .