CF1515I.Phoenix and Diamonds
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Phoenix wonders what it is like to rob diamonds from a jewelry store!
There are n types of diamonds. The i -th type has weight wi and value vi . The store initially has ai diamonds of the i -th type.
Each day, for q days, one of the following will happen:
- A new shipment of ki diamonds of type di arrive.
- The store sells ki diamonds of type di .
- Phoenix wonders what will happen if he robs the store using a bag that can fit diamonds with total weight not exceeding ci . If he greedily takes diamonds of the largest value that fit, how much value would be taken? If there are multiple diamonds with the largest value, he will take the one with minimum weight. If, of the diamonds with the largest value, there are multiple with the same minimum weight, he will take any of them.
Of course, since Phoenix is a law-abiding citizen, this is all a thought experiment and he never actually robs any diamonds from the store. This means that queries of type 3 do not affect the diamonds in the store.
输入格式
The first line contains two integers n and q ( 1≤n≤2⋅105 ; 1≤q≤105 ) — the number of types of diamonds and number of days, respectively.
The next n lines describe each type of diamond. The i -th line will contain three integers ai , wi , and vi ( 0≤ai≤105 ; 1≤wi,vi≤105 ) — the initial number of diamonds of the i -th type, the weight of diamonds of the i -th type, and the value of diamonds of the i -th type, respectively.
The next q lines contain the queries. For each query, the first integer of each line is t ( 1≤t≤3 ) — the type of query.
If t=1 , then two integers ki , di follow ( 1≤ki≤105 ; 1≤di≤n ). This means that a new shipment of ki diamonds arrived, each of type di .
If t=2 , then two integers ki , di follow ( 1≤ki≤105 ; 1≤di≤n ). This means that the store has sold ki diamonds, each of type di . It is guaranteed that the store had the diamonds before they sold them.
If t=3 , an integer ci will follow ( 1≤ci≤1018 ) — the weight capacity of Phoenix's bag.
It is guaranteed that there is at least one query where t=3 .
输出格式
Print the answer for each query of the third type ( t=3 ).
输入输出样例
输入#1
3 5 2 3 4 1 5 1 0 2 4 3 6 1 3 3 3 10 2 2 3 3 30
输出#1
8 16 13
说明/提示
For the first query where t=3 , Phoenix can fit 2 diamonds of type 1 , with total weight 6 and value 8 .
For the second query where t=3 , Phoenix will first fit in 3 diamonds of type 3 , then one diamond of type 1 for a total weight of 9 and a value of 16 . Note that diamonds of type 3 are prioritized over type 1 because type 3 has equal value but less weight.
For the final query where t=3 , Phoenix can fit every diamond for a total value of 13 .