GUPTA MECHANICAL

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

Friday 6 May 2022

Prof. Slim Codeforces Solution | Codeforces Problem Solution 2022

A. Prof. Slim
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

One day Prof. Slim decided to leave the kingdom of the GUC to join the kingdom of the GIU. He was given an easy online assessment to solve before joining the GIU. Citizens of the GUC were happy sad to see the prof leaving, so they decided to hack into the system and change the online assessment into a harder one so that he stays at the GUC. After a long argument, they decided to change it into the following problem.

Solution Click Below:-  CLICK HERE

Given an array of n integers a1,a2,,anwhere ai0, check if you can make this array sorted by using the following operation any number of times (possibly zero). An array is sorted if its elements are arranged in a non-decreasing order.

Prof. Slim Codeforces Solution | Codeforces Problem Solution 2022

Dorms War Codeforces Solution | Codeforces Problem Solution 2022

Where is the Pizza? Codeforces Solution | Codeforces Problem Solution 2022

Very Suspicious Codeforces Solution | Codeforces Problem Solution 2022

Hemose on the Tree Codeforces Solution | Codeforces Problem Solution 2022

Jee, You See? Codeforces Solution | Codeforces Problem Solution 2022


  1. select two indices i and j (1i,jn) such that ai and aj have different signs. In other words, one must be positive and one must be negative.
  2. swap the signs of ai and aj. For example if you select ai=3 and aj=2, then they will change to ai=3 and aj=2.

Prof. Slim saw that the problem is still too easy and isn't worth his time, so he decided to give it to you to solve.

Input

The first line contains a single integer t (1t104) — the number of test cases. Then t test cases follow.

The first line of each test case contains a single integer n (1n105) — the length of the array a.

The next line contain n integers a1,a2,,an (109ai109ai0) separated by spaces describing elements of the array a.

It is guaranteed that the sum of n over all test cases doesn't exceed 105.

Output

For each test case, print "YES" if the array can be sorted in the non-decreasing order, otherwise print "NO". You can print each letter in any case (upper or lower).

Join Now for Solution:- 

No comments:

Post a Comment