CodechefJun 17, 2025

A or B

Hazrat Ali

Codechef

There are two problems in a contest.

  • Problem A is worth 500 points at the start of the contest.
  • Problem B is worth 1000 points at the start of the contest.

Once the contest starts, after each minute:

  • Maximum points of Problem A reduce by 2 points .
  • Maximum points of Problem B reduce by 4 points.

It is known that Chef requires X minutes to solve Problem A correctly and Y minutes to solve Problem B correctly.

Find the maximum number of points Chef can score if he optimally decides the order of attempting both the problems.

Input Format

  • First line will contain T, number of test cases. Then the test cases follow.
  • Each test case contains of a single line of input, two integers X and Y - the time required to solve problems A and B in minutes respectively.

Output Format

For each test case, output in a single line, the maximum number of points Chef can score if he optimally decides the order of attempting both the problems.

Constraints

  • 1≤
  • 1

Sample 1:

Input
4
10 20
8 40
15 15
20 10

Output
1360
1292
1380
1400

Solution
T = int(input())
for _ in range(T):
    X, Y = map(int, input().split())
    score_A_first = max(0, 500 - 2 * X) + max(0, 1000 - 4 * (X + Y))
    score_B_first = max(0, 1000 - 4 * Y) + max(0, 500 - 2 * (X + Y))
    print(max(score_A_first, score_B_first))



 

Comments