DMOPC '19 Contest 1 P1 - Test Scores

View as PDF

Submit solution


Points: 5
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

Veshy is suffering in AP Physics! He has a series of N tests coming up and he has come up with four parameters describing each test:

  • ni which indicates the number of problems on the i-th test
  • ai which indicates the number of points Veshy gets for one correct answer
  • bi which indicates the number of points Veshy loses for an incorrect or unanswered question
  • ti which indicates the score Veshy would like to earn on the i-th test

For the i-th test, output the minimum number of questions Veshy has to answer correctly in order to get at least ti marks. If Veshy's standards are too high and he cannot get ti marks on the i-th test, then output -1.

Constraints

In all tests,
1N100
1ni,ai,bi,ti109

Input Specification

The first line contains one integer, N, the number of tests to follow.
The next N lines contain four space-separated integers, ni ai bi ti.

Output Specification

Output N lines. The i-th line should contain one integer, the answer to the i-th test.

Sample Input

Copy
5
1 4 2 5
9 2 6 4
2 9 3 5
3 5 2 10
8 2 5 7

Sample Output

Copy
-1
8
1
3
7

Comments


  • -1
    IanHu  commented on Oct. 6, 2019, 4:59 p.m.

    Somebody help check my code plzz


    • 3
      Y  commented on Oct. 12, 2019, 10:07 p.m. edit 2

      The value of b×n can go up to 1018, which exceeds the maximum value for int (2311) in java. Edit: Also you may want to see if there is a way to get the value of j in a faster way.


    • -2
      mibster  commented on Oct. 6, 2019, 5:16 p.m.

      The answer may overflow int