GUPTA MECHANICAL

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

Sunday 5 June 2022

[Solution] Split AND Sum CodeChef Solution | CodeChef Problem Solution 2022

You are given an array [A1,,AN]. You want to split it into several (2) subarrays so that the following condition holds:

  • Calculate the sum of elements in each subarray. Then, the AND of all these sums is nonzero, where AND denotes the bitwise AND operation.

Determine if it's possible. If it's possible, find one such split. You don't 

Solution Click Below:-  CLICK HERE


have to minimize the number of subarrays.

Input Format

  • The first line of the input contains a single integer T  the number of test cases. The description of the test cases follows.
  • The first line of each test case contains a single integer N  the length of the array.

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

Output Format

For each test case, if it's not possible to split the array so that the condition from the statement holds, output NO.

Otherwise, output YES. In the next line, output K (2KN the number of subarrays you are splitting into.

In the i-th of the next K lines, output two integers Li,Ri (1LiRiN), where [Li,Ri] denotes the i-th subarray.

Each number from 1 to N has to appear in exactly one of the segments [Li,Ri].

You can output each letter in either uppercase or lowercase. You can output any solution. You don't have to minimize K.

Constraints

  • 1T105
  • 2N105
  • 0Ai<230
  • Sum of N over all test cases doesn't exceed 

No comments:

Post a Comment