题库练习 Perun, Ult!
← 上一题 下一题 →

A11525 | Perun, Ult!

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

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 ![](/uploads/luogu/CF912C/d216f79c4581ff07bac2eb40367610feb8c137c2_963168173bdb.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 ![](/uploads/luogu/CF912C/2078a0964de47cdee5ccf9b3fbbb9c2602fdb150_a19682c2832d.png). Additionally, it increases by ![](/uploads/luogu/CF912C/600a44120274d855b208352694b857991b9552e9_33d53ee4a95f.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 ![](/uploads/acgo/image/917a11806cf53df3_e0ce79c11266.jpeg) 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:

- ![](/uploads/acgo/image/732b4b4cb52cb5c9_bc7dc2837f27.jpeg) — maximum number of health points for the $i$ -th enemy;
- ![](/uploads/acgo/image/959b889884ce76ba_bdaf21c61473.jpeg) — initial health of the enemy (on the $0$ -th second);
- ![](/uploads/acgo/image/6e0d9531bc1e5861_d88ff05edfaf.jpeg) — the amount of health the $i$ -th enemy can regenerate per second.

There also $m$ health updates Vlad knows about:

- ![](/uploads/acgo/image/84242f9b334bde2b_6f11f7ed6468.jpeg) — time when the health was updated;
- ![](/uploads/acgo/image/5002c8e766558fdc_bb0d7abc97b6.jpeg) — the enemy whose health was updated;
- ![](/uploads/acgo/image/c44f4a8af319d0d8_9d311dc77da4.jpeg) — 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: ![](/uploads/luogu/CF912C/2078a0964de47cdee5ccf9b3fbbb9c2602fdb150_a19682c2832d.png), ![](/uploads/luogu/CF912C/600a44120274d855b208352694b857991b9552e9_33d53ee4a95f.png) and ![](/uploads/luogu/CF912C/d216f79c4581ff07bac2eb40367610feb8c137c2_963168173bdb.png) (![](/uploads/luogu/CF912C/42e040fdd42ccab03e8b01582adfbc4187ba2e5a_f1f5578b8c64.png), ![](/uploads/acgo/image/2b5b7fa5d46fef59_4d170564a4f8.jpeg)).

Each of the following $n$ lines has three integers — ![](/uploads/luogu/CF912C/fc4707d8a855c477b62b13b1470d38bb6766fbc9_89abd2e2d10d.png), ![](/uploads/luogu/CF912C/8efcccd354ad1e78851168f9dfe9981ef086b631_9deaef661777.png), ![](/uploads/luogu/CF912C/dce4274c465d132023523d8a7f53bc4a706d2722_87e69093a637.png) (![](/uploads/luogu/CF912C/59dda9e4057a39c10efc1bcfd88cd6f78d3c2f61_f1ec5b69c87d.png), ![](/uploads/acgo/image/8a2bfa8e45f98040_9f5427def43a.jpeg)).

The next $m$ lines contain three integers each — ![](/uploads/luogu/CF912C/085949a0fef92cec2ad6a8413640d4367b22ea30_4199a0fec46b.png), ![](/uploads/luogu/CF912C/b2ad7de3b3b780b7804e20a0428f7e5181e4453b_3c9bc80f5ed4.png), ![](/uploads/luogu/CF912C/fa9c2a28c567ce2c3bc995acf7706c9f11229fd1_5f79ed09eeb1.png) (![](/uploads/luogu/CF912C/49044c342501f49c2f2c0570193e2518a2566e8f_13edb71bfed1.png), ![](/uploads/luogu/CF912C/47a8930a047ba4efbaf47adc40a60ae6e4d1ef8f_7eaf79c005cc.png), ![](/uploads/luogu/CF912C/c009f9899384ba40075c57b9015ebb303aa428d7_a60963f1c6d7.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 ![](/uploads/luogu/CF912C/f1fee912a178bb7fd6a712750d22cb4ed1a3e85e_b2040ea384e4.png), then ![](/uploads/acgo/image/a7d7c9b9e6125216_76a59203492c.jpeg).

输出格式

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
C++ 编辑器
输入
输出