CF1413E.Solo mid Oracle

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Meka-Naruto plays a computer game. His character has the following ability: given an enemy hero, deal aa instant damage to him, and then heal that enemy bb health points at the end of every second, for exactly cc seconds, starting one second after the ability is used. That means that if the ability is used at time tt , the enemy's health decreases by aa at time tt , and then increases by bb at time points t+1t + 1 , t+2t + 2 , ..., t+ct + c due to this ability.

The ability has a cooldown of dd seconds, i. e. if Meka-Naruto uses it at time moment tt , next time he can use it is the time t+dt + d . Please note that he can only use the ability at integer points in time, so all changes to the enemy's health also occur at integer times only.

The effects from different uses of the ability may stack with each other; that is, the enemy which is currently under kk spells gets kbk\cdot b amount of heal this time. Also, if several health changes occur at the same moment, they are all counted at once.

Now Meka-Naruto wonders if he can kill the enemy by just using the ability each time he can (that is, every dd seconds). The enemy is killed if their health points become 00 or less. Assume that the enemy's health is not affected in any way other than by Meka-Naruto's character ability. What is the maximal number of health points the enemy can have so that Meka-Naruto is able to kill them?

输入格式

The first line contains an integer tt ( 1t1051\leq t\leq 10^5 ) standing for the number of testcases.

Each test case is described with one line containing four numbers aa , bb , cc and dd ( 1a,b,c,d1061\leq a, b, c, d\leq 10^6 ) denoting the amount of instant damage, the amount of heal per second, the number of heals and the ability cooldown, respectively.

输出格式

For each testcase in a separate line print 1-1 if the skill can kill an enemy hero with an arbitrary number of health points, otherwise print the maximal number of health points of the enemy that can be killed.

输入输出样例

  • 输入#1

    7
    1 1 1 1
    2 2 2 2
    1 2 3 4
    4 3 2 1
    228 21 11 3
    239 21 11 3
    1000000 1 1000000 1

    输出#1

    1
    2
    1
    5
    534
    -1
    500000500000

说明/提示

In the first test case of the example each unit of damage is cancelled in a second, so Meka-Naruto cannot deal more than 1 damage.

In the fourth test case of the example the enemy gets:

  • 44 damage ( 11 -st spell cast) at time 00 ;
  • 44 damage ( 22 -nd spell cast) and 33 heal ( 11 -st spell cast) at time 11 (the total of 55 damage to the initial health);
  • 44 damage ( 33 -nd spell cast) and 66 heal ( 11 -st and 22 -nd spell casts) at time 22 (the total of 33 damage to the initial health);
  • and so on.

One can prove that there is no time where the enemy gets the total of 66 damage or more, so the answer is 55 . Please note how the health is recalculated: for example, 88 -health enemy would not die at time 11 , as if we first subtracted 44 damage from his health and then considered him dead, before adding 33 heal.

In the sixth test case an arbitrarily healthy enemy can be killed in a sufficient amount of time.

In the seventh test case the answer does not fit into a 32-bit integer type.

首页