GUPTA MECHANICAL

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

Wednesday 8 June 2022

[Solution] Sorting Array CodeChef Solution | CodeChef Problem Solution 2022

Given an array A of length N.

You are allowed to perform the following operation on the array A atmost 20 times:

  • Select a non-empty http://subsequence S of the array [1,2,3,,N] and an integer X (0X106);
  • Change Ai to Ai+X for all iS.

You have to sort the array A in strictly increasing order by performing atmost 20 operations.

It is guaranteed that we can always sort the array A under given constraints.

Input Format

  • The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follow.
Solution Click Below:-  CLICK HERE


  • The first line of each test case contains an integer N - the length of the array.
  • The second line of each test case contains N space-separated integers A1,A2,,AN representing the initial array A.

Output Format

For each test case print (2Q+1) lines. Here Q denotes the number of operations you performed to sort the array A. Note that, Q must be less than or equal to 20. For each test case,









  • In the first line, print Q, the number of operations you perform.
  • Then, print 2Q lines. The (2i1)th and (2i)th of these lines denote the ith (1iQ) operation.

To describe the ith operation, print two space-separated integers Ki(1KiN) and Xi(0Xi106) on (2i1)th line and print Ki space-separated integers describing subsequence Si on (2i)th line.

Constraints

  • 1T5104
  • 2N105
  • 1Ai105
  • Sum of N over all test cases does not exceed 105.

No comments:

Post a Comment