#abc287g. G - Balance Update Query
G - Balance Update Query
Score : points
问题描述
Takahashi 拥有 张每种类型的卡片,共有 种类型。最初,第 种类型的卡片的得分和限额分别设置为 和 。
接下来将按照以下格式接收并处理 个查询请求:
1 x y
: 将第 种类型的卡片得分设置为 。2 x y
: 将第 种类型的卡片限额设置为 。3 x
: 如果在满足以下条件下可以选择 张卡片,则输出所选卡片得分的最大可能总和;否则输出-1
。- 每种类型的卡片选择数量不超过其限额。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Takahashi has cards of each of kinds. Initially, the score and quota of the -th kind of card are set to and , respectively.
Given queries in the following formats, process them in order.
1 x y
: set the score of the -th kind of card to .2 x y
: set the quota of the -th kind of card to .3 x
: if one can choose cards subject to the following condition, print the maximum possible sum of the scores of the chosen cards; print-1
otherwise.- The number of chosen cards of each kind does not exceed its quota.
Constraints
- For each query of the -st kind, and .
- For each query of the -nd kind, and .
- For each query of the -rd kind, .
- There is at least one query of the -rd kind.
- All values in the input are integers.
Input
The input is given from Standard Input in the following format, where denotes the -th query:
Output
Print lines, where is the number of queries of the -rd kind.
The -th line should contain the response to the -th such query.
Sample Input 1
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
Sample Output 1
11
19
-1
4
For the first query of the -rd kind, you can choose one card of the -nd kind and three cards of the -rd kind for a total score of , which is the maximum.
For the second such query, you can choose one card of the -st kind and three cards of the -rd kind for a total score of , which is the maximum.
For the third such query, you cannot choose four cards, so -1
should be printed.
For the fourth such query, you can choose two cards of the -nd kind for a total score of , which is the maximum.
update @ 2024/3/10 12:00:48