SMPSEQ7 - Fun with Sequences (Act 5)


You are given S - a sequence of n integers S = s1, s2 ... sn. Please, compute if it is possible to split S into two parts: s1, s2 ... si and si+1, si+2 ... sn (1 <= i < n) in such a way that the first part is strictly decreasing while the second is strictly increasing one.

Input data specification

In the first line you are given an integer 2 <= n <= 100 and in the following line n integers
-100 <= si <= 100.

Output data specification

One word Yes or No.

Example 1

Input:
5
-1 2 -1 1 -1

Output:
No

Example 2

Input:
6
3 1 -2 -2 -1 3

Output:
Yes

Example 3

Input:
6
2 2 1 0 1 2

Output:
No

hide comments
martian_1: 2020-08-25 07:45:10

easy peasy!
AC in one GO

vikas0104: 2020-03-31 10:17:43

my program is running fine with the above three examples but spoj is showing wrong answer while submission
i have taken care of multiple instances of a number
and also taken care of single-element array...
what else am i missing...??

Last edit: 2020-03-31 10:19:31
krish_47: 2018-11-29 11:40:25

Nice problem.. AC in one shot. :)

arunsai63: 2017-01-26 19:15:06

got accepted after a few tries...
1-mainly we have to consider the strictly increasing and decreasing part....if the consecutive numbers are equal then they are not strictly increasing/decreasing
2-some are asking there are two possibilities...the question clearly stated that if possible then print YES....if YES yes if possible by any means then print YES...
3-any of the increasing or deceasing parts can contain 1 element...
4-try to dry run your code(using pen and paper ) try manually step by step and try to figure out the problem
5-if all the examples are working in your program but the judge doesnt accept or saying wrong answer the try to optimise your code bye considering all possible cases etc...(other than the given examples)

Last edit: 2017-01-26 19:17:58
gary771016: 2016-09-23 17:24:55

@d73_221b
example 3: [2 2 1 0 1 2]
since 2->2 (no decreasing), so answer is "NO"

@lekov
if one of all answers is "Yes" ,we print "Yes"
if all answers are "No",we print "No"
so your example [4 3 2 1 -3 -2 -1 ] ,we print "Yes"

Last edit: 2016-09-23 17:25:14
d73_221b: 2016-09-05 11:37:23

In example 3,
[2 2 1 0 1 2]
{2, 2, 1, 0} - {1, 2}
{2, 2, 1} - {0, 1, 2}
Both are valid. So the answer should be YES, why is it NO?

lekov: 2016-07-02 22:10:50

4 3 2 1 -3 -2 -1

We can have it divided like this
{4, 3, 2}, {1, -3, -2, -1} and print No

or like this
{4, 3, 2, 1}, {-3, -2, -1} and print Yes

Which one should we use?

Last edit: 2016-07-11 11:12:48
mayank_06: 2016-05-15 13:59:29

My logic was that
if n=2 or n=3 then no should be printed as single element cannot be increasing or decreasing.
if n>3 and if any element's count >2 then answer is no, otherwise yes.
it is working fine on dev c++ as well as on ideone but still judge shows wrong answer.

mauro8707_java: 2016-05-06 01:45:17

How can I see the test proccess? I can't figure it out why my algorithm doesn't work.

pailuf_42: 2016-03-02 16:07:41

@raghavdua For n it says 2<=n<=100, so I'm guessing you are allowed to do that.


Added by:kuszi
Date:2013-12-12
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64