GUPTA MECHANICAL

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

Friday, 24 June 2022

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


Chef is deriving weird ways to sort his array. Currently he is trying to sort his arrays in increasing order by reversing some of his subarrays.
To make it more challenging for himself, Chef decides that he can reverse only those subarrays that have sum of its elements at most X. Soon he notices that it might not be always possible to sort the array with this condition.
Can you help the Chef by telling him if the given array can be sorted by reversing subarrays with sum at most X.
More formally, for a given array A and an integer X, check whether the array can be sorted in increasing order by reversing some (possibly none) of the
Solution Click Below:-  👉CLICK HERE👈
👇👇👇👇👇

 

subarrays such that the sum of all elements of the subarray is at most X.

Input Format

  • First line will contain T, number of test cases. Then the test cases follow.
  • The first line of each test case contains of two space-separated integers N and X denoting the length of the array and the maximum sum of subarrays that you can reverse.
  • The second line contains N space-separated integers A1,A2,...,AN representing the initial array.

Output Format

For each test case, output YES if Chef can sort the array using a finite number of operations, else output NO.

You may print each character of the string in uppercase or lowercase (for example, the strings YeSyEsyes and YES will all be treated as identical).

Constraints

  • 1T5104
  • 1N105
  • 1Ai2109
  • 1X2109
  • Sum of N over all test cases does not exceeds 3105.

No comments:

Post a Comment