CF1266E Spaceship Solitaire
题目描述
## 题意翻译
Bob在玩一款叫*Spaceship Solitaire*的游戏。游戏的核心是建造一艘宇宙飞船。为了建造,他首先需要积累足够的资源。有$n$种资源,从$1$到$n$标号,Bob需要$a_i$个第$i$种资源来建造飞船。我们称$a_i$为资源$i$的目标。
一回合能且只能生产一个资源。但是,有一些“成就”可以加快生产速度。每个成就可以用一个三元组表示$(s_j, t_j, u_j)$,意思是当Bob拥有的第$s_j$种资源个数达到$t_j$时,他可以获得1个免费的第$u_j$种资源。获得此免费资源有可能使Bob要求获得另一个成就的奖励。
不会有两个成就含有相同的$s_j$和$t_j$,也就是说,达到资源$t_j$个资源$s_j$的奖励最多是一个额外的资源。
对于每个成就,有$0 < t_j < a_{s_j}$
达到一定资源量的奖励可以是这个资源本身,也就是$s_j = u_j$
最开始时没有成就的。你需要处理$q$次更新,可能是添加,删除或改变成就。在每次更新后,输出完成游戏(也就是对于每个资源$i \in [1, n]$,收集至少$a_i$个)所需的最小回合数。
输入格式
无
输出格式
无
说明/提示
After the first update, the optimal strategy is as follows. First produce $ 2 $ once, which gives a free resource $ 1 $ . Then, produce $ 2 $ twice and $ 1 $ once, for a total of four turns.
After the second update, the optimal strategy is to produce $ 2 $ three times — the first two times a single unit of resource $ 1 $ is also granted.
After the third update, the game is won as follows.
- First produce $ 2 $ once. This gives a free unit of $ 1 $ . This gives additional bonus of resource $ 1 $ . After the first turn, the number of resources is thus $ [2, 1] $ .
- Next, produce resource $ 2 $ again, which gives another unit of $ 1 $ .
- After this, produce one more unit of $ 2 $ .
The final count of resources is $ [3, 3] $ , and three turns are needed to reach this situation. Notice that we have more of resource $ 1 $ than its goal, which is of no use.