304783: CF912C. Perun, Ult!

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Perun, Ult!

题意翻译

Vlad 在他最喜欢的MOBA游戏中扮演一个名为Perun的英雄。 Perun有一个称为“Thunderwrath”的技能。在释放的瞬间,地图上的每个敌人(总共有$n$个)失去一部分生命值 $damage$ 。它也有一个限制:它只能在时间为整数时激活。杀死敌人会获得赏金 $dounty$。另外,赏金每秒增加 $increase$。如果在$t$秒时技能被释放,并且第$i$个敌人因此丧生(即生命值降至$0$或更低),Vlad获得会获得 $bounty + t \cdot increase$ 这么多的赏金。 每个敌人都可以受到伤害,也可以得到治疗。对于n个敌人中的每一个敌人,Vlad知道: - $max\_health_i$ ——第 $i$个敌人的最大生命值 - $start\_health_i$ ——敌人的初始健康状态(第$0$秒时); - $regen_i$ ——第$i$个敌人每秒回复的生命值。 Vlad 还知道 $m$ 条关于生命值更新的信息: - $time_j$ ——生命只被更新的时间; - $enemy_j$ ——生命值更新的敌人编号; - $health_j$ —- $enemy_j$ 更新后的生命值。 很明显,Vlad想要最大化他的收益。如果有必要的话,他甚至可以等待几年才释放他的技能。帮助他确定他能获得的最大赏金(注意它必须是一个整数)$0$ 到 $+\infty$,这样一次技能的释放就会产生最大的赏金,输出这个赏金数。 由 @ThunderLightning 提供翻译

题目描述

A lot of students spend their winter holidays productively. Vlad has advanced very well in doing so! For three days already, fueled by salads and tangerines — the leftovers from New Year celebration — he has been calibrating his rating in his favorite MOBA game, playing as a hero named Perun. Perun has an ultimate ability called "Thunderwrath". At the instant of its activation, each enemy on the map ( $ n $ of them in total) loses ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/d216f79c4581ff07bac2eb40367610feb8c137c2.png) health points as a single-time effect. It also has a restriction: it can only activated when the moment of time is an integer. The initial bounty for killing an enemy is ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/2078a0964de47cdee5ccf9b3fbbb9c2602fdb150.png). Additionally, it increases by ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/600a44120274d855b208352694b857991b9552e9.png) each second. Formally, if at some second $ t $ the ability is activated and the $ i $ -th enemy is killed as a result (i.e. his health drops to zero or lower), Vlad earns ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/2affc6d4bcb10dc0ae3b3c9c0c973c94780f368d.png) units of gold. Every enemy can receive damage, as well as be healed. There are multiple ways of doing so, but Vlad is not interested in details. For each of $ n $ enemies he knows: - ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/fc4707d8a855c477b62b13b1470d38bb6766fbc9.png) — maximum number of health points for the $ i $ -th enemy; - ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/8efcccd354ad1e78851168f9dfe9981ef086b631.png) — initial health of the enemy (on the $ 0 $ -th second); - ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/dce4274c465d132023523d8a7f53bc4a706d2722.png) — the amount of health the $ i $ -th enemy can regenerate per second. There also $ m $ health updates Vlad knows about: - ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/085949a0fef92cec2ad6a8413640d4367b22ea30.png) — time when the health was updated; - ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/b2ad7de3b3b780b7804e20a0428f7e5181e4453b.png) — the enemy whose health was updated; - ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/fa9c2a28c567ce2c3bc995acf7706c9f11229fd1.png) — updated health points for $ enemy_{j} $ . Obviously, Vlad wants to maximize his profit. If it's necessary, he could even wait for years to activate his ability at the right second. Help him determine the exact second (note that it must be an integer) from $ 0 $ (inclusively) to $ +∞ $ so that a single activation of the ability would yield Vlad the maximum possible amount of gold, and print this amount.

输入输出格式

输入格式


In the first line, two integers are given (separated by spaces) — $ n $ and $ m $ ( $ 1<=n<=10^{5} $ , $ 0<=m<=10^{5} $ ). In the second line, there are three integers: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/2078a0964de47cdee5ccf9b3fbbb9c2602fdb150.png), ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/600a44120274d855b208352694b857991b9552e9.png) and ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/d216f79c4581ff07bac2eb40367610feb8c137c2.png) (![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/42e040fdd42ccab03e8b01582adfbc4187ba2e5a.png), ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/8a4e75cb84353cc36593ece6ef0d3a853e7c0a32.png)). Each of the following $ n $ lines has three integers — ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/fc4707d8a855c477b62b13b1470d38bb6766fbc9.png), ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/8efcccd354ad1e78851168f9dfe9981ef086b631.png), ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/dce4274c465d132023523d8a7f53bc4a706d2722.png) (![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/59dda9e4057a39c10efc1bcfd88cd6f78d3c2f61.png), ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/8ca6cefe9cfdd645cbe6b06164210f3b6a0a6046.png)). The next $ m $ lines contain three integers each — ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/085949a0fef92cec2ad6a8413640d4367b22ea30.png), ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/b2ad7de3b3b780b7804e20a0428f7e5181e4453b.png), ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/fa9c2a28c567ce2c3bc995acf7706c9f11229fd1.png) (![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/49044c342501f49c2f2c0570193e2518a2566e8f.png), ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/47a8930a047ba4efbaf47adc40a60ae6e4d1ef8f.png), ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/c009f9899384ba40075c57b9015ebb303aa428d7.png)). It is guaranteed that there is no more than one hearth change per second for each enemy: more formally, for each $ a,b $ so that $ 1<=a,b<=m,a≠b $ holds that if ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/f1fee912a178bb7fd6a712750d22cb4ed1a3e85e.png), then ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/06e6840652f0042b773959120bd2bd7e646960cb.png).

输出格式


Output the single integer — the maximum amount of gold Vlad can obtain if he applies "Thunderwrath" exactly once, or -1 if this amount can be infinitely large.

输入输出样例

输入样例 #1

3 2
1000 10 50
70 5 5
90 70 1
110 20 2
20 2 10
30 3 10

输出样例 #1

3000

输入样例 #2

1 1
500 50 1000
750 750 20
10 1 300

输出样例 #2

-1

说明

On the pictures you can see health points of each enemy versus time in sample cases. Periods when Vlad can kill one enemy are marked with yellow color. Periods when Vlad can kill two enemies are marked with purple color. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/371bebe0ea750379826870ee127df5b588d49620.png)In the first sample case, Vlad can activate the ability at the $ 50 $ -th second: the enemies $ 2 $ and $ 3 $ will die since they would have $ 40 $ and $ 50 $ health points correspondingly. Vlad will earn $ 2·(1000+50·10)=3000 $ gold. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF912C/dee22bf9a2821d482ba5ff5de6e1cf1db497ba51.png)In the second sample case, the maximum amount of health for the enemy $ 1 $ is less than the damage dealt by the ability. Hence, the enemy could be killed anytime. As the bounty increases by $ 50 $ over the time, the maximum possible amount of gold is infinite.

Input

题意翻译

Vlad 在他最喜欢的MOBA游戏中扮演一个名为Perun的英雄。 Perun有一个称为“Thunderwrath”的技能。在释放的瞬间,地图上的每个敌人(总共有$n$个)失去一部分生命值 $damage$ 。它也有一个限制:它只能在时间为整数时激活。杀死敌人会获得赏金 $dounty$。另外,赏金每秒增加 $increase$。如果在$t$秒时技能被释放,并且第$i$个敌人因此丧生(即生命值降至$0$或更低),Vlad获得会获得 $bounty + t \cdot increase$ 这么多的赏金。 每个敌人都可以受到伤害,也可以得到治疗。对于n个敌人中的每一个敌人,Vlad知道: - $max\_health_i$ ——第 $i$个敌人的最大生命值 - $start\_health_i$ ——敌人的初始健康状态(第$0$秒时); - $regen_i$ ——第$i$个敌人每秒回复的生命值。 Vlad 还知道 $m$ 条关于生命值更新的信息: - $time_j$ ——生命只被更新的时间; - $enemy_j$ ——生命值更新的敌人编号; - $health_j$ —- $enemy_j$ 更新后的生命值。 很明显,Vlad想要最大化他的收益。如果有必要的话,他甚至可以等待几年才释放他的技能。帮助他确定他能获得的最大赏金(注意它必须是一个整数)$0$ 到 $+\infty$,这样一次技能的释放就会产生最大的赏金,输出这个赏金数。 由 @ThunderLightning 提供翻译

加入题单

上一题 下一题 算法标签: