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 (0≤X≤106);
  • Change Ai to Ai+X for all i∈S.

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 (2⋅Q+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 2⋅Q lines. The (2⋅i−1)th and (2⋅i)th of these lines denote the ith (1≤i≤Q) operation.

To describe the ith operation, print two space-separated integers Ki(1≤Ki≤N) and Xi(0≤Xi≤106) on (2⋅i−1)th line and print Ki space-separated integers describing subsequence Si on (2⋅i)th line.

Constraints

  • 1≤T≤5⋅104
  • 2≤N≤105
  • 1≤Ai≤105
  • Sum of N over all test cases does not exceed 105.

No comments:

Post a Comment