Need help in codeforces div2 round 672 problem A

This was my 1st submission to the problem however it failed in test case 2 . Can someone plz help in finding the bug ?

Question link -

Solution link -

1 Like

You can see the editorial… & as per your code…you should cut off the reverse and sorting part…and if(a[i]!=b[i]) change it with a[i]>=a[i+1] and run the loop from i=0 to i=n-1

1 Like

If all values are distinct and input is in descending order only then the answer is “NO”. otherwise answer is “YES”. You are checking second condition with “flag”. But there is a bug for the first condition. You should try “s.size() < n” (it means there is at least one duplicate value). Hopefully it will be accepted then. :blush:

1 Like

my submission gave TLE for test 19 i think

if numbers are in stricktly decreasing order then “NO” otherwise “YES”

1 Like

For the answer to be “NO”, two conditions should be strictly satisfied

  1. The sequence should have all unique numbers

  2. The sequence should be in sorted in the non-increasing order
    If you want your code to work properly use just change to the condition below:-

    if(flag==0 && s.size()==n)

Tip: Use “\n” instead of endl for faster printing :slight_smile:

1 Like

Thnx man , just a change in sign woukd have saved me from rewriting the entire code.