After the Earth Queen fell, the Earth Kingdom fell into anarchy and was overrun by bandits. Luckily for the citizens of the Earth Kingdom, Kuvira the Great Uniter has brought security to the new Earth Empire and wishes to reconnect the nation by building bridges. She thinks that bridges symbolize power and wealth and will be necessary in rebuilding Republic City.
The Earth Empire consists of
After losing her smartest engineer and nuking her second smartest engineer, Kuvira has been left engineer-less (and fiance-less). Seeing the opportunity for a big time promotion, you decide to help her count the number of different bridges that she can build between
Hint 1
Use a stack!
Hint 2
Note that each bridge that can be made has a left and a right hill. Consider a right hill
Input Specification
The first line will contain the integer
The next
The heights of the hills will be given in order.
Output Specification
Print a single integer, the number of distinct bridges that can be built between
Sample Input
5
2
10
5
7
10
Sample Output
6
Comments
there should be an explanation for the sample input for more clarity tbh
Any hints on how to improve my solution? Is my idea even correct in the first place?
I'd also try "A Classic problem".
edit: oops you solved it a second few i posted this comment
I don't think your solution would work even if you optimize. (Time complexity is similar to
)
Try using a stack instead for an
time complexity.
Here is a similar problem that might help you solve this one: https://dmoj.ca/problem/mwc15c2p2
For the sample Input/Output please.
2-->10
10-->5 10-->7 10-->10
5-->7
7-->10
omaewamoushindeiru do you get it? Basically if all the stuff in the middle of the outer ones are less than or equal to both the outer ones, you can build a bridge.
It would be really cool if we could also have other themed contests as time goes on, like a Doctor Who or Sherlock (none of that Elementary crap) contest!
:3
Unfortunately, those of us who make the contest are losers and have not watched any of those :(
It's okay, my contests are almost guaranteed to be full of spoilers about ongoing anime.