CF912C.Perun, Ult!

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 ( nn of them in total) loses 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 . Additionally, it increases by each second. Formally, if at some second tt the ability is activated and the ii -th enemy is killed as a result (i.e. his health drops to zero or lower), Vlad earns 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 nn enemies he knows:

  • — maximum number of health points for the ii -th enemy;
  • — initial health of the enemy (on the 00 -th second);
  • — the amount of health the ii -th enemy can regenerate per second.

There also mm health updates Vlad knows about:

  • — time when the health was updated;
  • — the enemy whose health was updated;
  • — updated health points for enemyjenemy_{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 00 (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) — nn and mm ( 1<=n<=1051<=n<=10^{5} , 0<=m<=1050<=m<=10^{5} ).

In the second line, there are three integers: , and (, ).

Each of the following nn lines has three integers — , , (, ).

The next mm lines contain three integers each — , , (, , ). It is guaranteed that there is no more than one hearth change per second for each enemy: more formally, for each a,ba,b so that 1<=a,b<=m,ab1<=a,b<=m,a≠b holds that if , then .

输出格式

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.

In the first sample case, Vlad can activate the ability at the 5050 -th second: the enemies 22 and 33 will die since they would have 4040 and 5050 health points correspondingly. Vlad will earn 2(1000+5010)=30002·(1000+50·10)=3000 gold.

In the second sample case, the maximum amount of health for the enemy 11 is less than the damage dealt by the ability. Hence, the enemy could be killed anytime. As the bounty increases by 5050 over the time, the maximum possible amount of gold is infinite.

首页