SPCU - Gopu and Validity of Arrangement
N persons are standing in a line. Height of each person is between 1 and N and height of each person is distinct.
You are given an array A where A[i] denotes how many persons are there before the i_th person having heights greater than the height of the ith person. For a person i, all the persons from 1 to i - 1 are considered to be before him. eg, For person 2, person 1 is considered before him.
You have to find out whether this array can be valid for some arrangement of persons. If you can uniquely do so then output "YES" Otherwise output "NO".
First line contains T : number of test cases. (1 <= T <= 20).
For each test First line contains an integer n. ( 1 <= N <= 10^5)
Next line contains n space seperated integers denoting A[i]. (0 <= A[i] <= N)
For each test case, output "YES" or "NO" according to answer.
For the first test case, [2, 1] is a valid case, First person has height 2, second person has height 1.
For the second test case, no valid test case exists.
Lol, confidence booster :P
AC in 1st go after a reaaaallly long time,seriously needed that confidence :)
Very easy one.
cin/cout = WA, scanf = AC .... Same logic
Last edit: 2014-09-29 20:13:57
I think the input is not filtered. Be very careful while using fast io.
easy one ...:)
easy once you get it.
what would be the answer for 0 0