GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Sunday 15 May 2022

[Solution] Maximum Pairwise Modular Sum CodeChef Solution | CodeChef Problem Solution 2022

You are given an array A containing N integers, and a positive integer M. Find the maximum value of

Ai+Aj+((AiAj)modM)

across all pairs 1i,jN.

Solution Click Below:-  CLICK HERE

Note that xmodM refers to the smallest non-negative integer obtained as the remainder upon dividing x by M. For example, 4mod3=1 and (10)mod3=2.

Input Format

  • The first line of input will contain a single integer T, the number of test cases. The description of test cases follows.
  • Each test case consists of two lines of input.

  • The first line of each test case contains two space-separated integers N and M.
  • The second line of each test case contains N space-separated integers A1,A2,,AN.

Output Format

Solution Click Below:-  CLICK HERE

  • For each test case, output on a new line the maximum value of Ai+Aj+((AiAj)modM).

Constraints

  • 1T100
  • 2N2105
  • 2M5108
  • 0Ai5108
  • The sum of N across all test cases won't exceed 2105.

Subtasks

  • Subtask 1 (10 points):
    • The sum of N across all test cases won't exceed 1000
  • Subtask 2 (20 points):
    • 2M1000
  • Subtask 3 (70 points):
    • Original constraints
Solution Click Below:-  CLICK HERE

No comments:

Post a Comment