Slow Solution 1 Problem Code: SLOWSOLN Chef is trying to solve a problem having T test cases, where, for each test case
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
Slow Solution 1 Problem Code: SLOWSOLN Chef is trying to solve a problem having T test cases, where, for each test case
Slow Solution 1 Problem Code: SLOWSOLN Chef is trying to solve a problem having T test cases, where, for each test case he is given a single integer N. Chef has an algorithm which takes exactly N2 iterations for a test case with value N. The constraints of the problem are as follows: •1≤T≤ maxT •1<N<max N Sum of N over all test cases does not exceed sum N.
Given the values maxT, max N, and sum N, determine the maximum number of iterations Chef's algorithm can take for any valid input file satisfying all the constraints. Formally speaking, find the maximum value of N2 + N² + ... + N² for any valid input file satisfying all the constraints. Input Format • The first line of input will contain a single integer T, denoting the number of test cases. • Each test case consists of single line consisting of three integers maxT, maxN, and sum N. D
Output Format For each test case, output the the maximum number of iterations Chef's algorithm can take in any valid test file. Constraints • 1≤T≤ 1000 • 1≤ maxT≤ maxN ≤ sumN ≤ 10¹ Sample Input 1 4 10 100 200 3 10 100 1000 1000 2200 100 100 100 Sample Output 1 20000 300 2040000 10000 G 7
Explanation Test Case 1: Worst case for Chef's algorithm would be where T = 2 and 100 for both the test cases. In this case, Chef's algorithm will take 100² +100² = 20000 iterations. N = Test Case 2: Worst case for Chef's algorithm would be where T = 3 and N = 10 for all the 3 test cases. In this case, Chef's algorithm will take 10² +10² + 10² = 300 iterations. Test Case 3: Worst case for Chef's algorithm would be where T = 3 and 1000, 1000, and 200 for the three test cases respectively. In this case, Chef's algorithm will take 1000² +1000² +200² 2040000 iterations. = 1 and Test Case 4: Worst case for Chef's algorithm would be where T N = 100. In this case Chef's algorithm will take 100² = 10000 iterations. =