San
Time limit1sMemory limit64 MB
Count subsets of skyscrapers forming a non-decreasing-height left-to-right jump sequence whose gold sum reaches at least K.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Combinatorics, Sorting
- Solved
- No attempts yet
Problem
Have you ever dreamt that you were the main character in a computer game? Branimir, the protagonist of this story, is having that dream right now.
The world in Branimir's dream consists of skyscrapers lined up from left to right. Skyscraper has height , and gold coins lie on its roof.
The game starts when Branimir jumps onto any one of the skyscrapers, and it continues through a number of steps. In one step Branimir can jump onto a skyscraper that stands to the right of the one he is on and is not lower than it. He may jump over the skyscrapers in between. On every roof he lands on, he collects all the gold coins. He can end the game after any number of steps, zero included, but he must collect at least gold coins to advance to the next level.
Count the number of different ways for Branimir to play the game and advance to the next level. Two games are different if some skyscraper is visited in one of them and not in the other.
Input
The first line contains integers and (, ).
The -th of the next lines contains integers and (), describing skyscraper .
Output
Print the number of different ways to play the game and advance to the next level.
Hint
In the first example there are three ways to advance. Written as the labels of the visited skyscrapers, they are {1, 2, 3}, {1, 4} and {4}.