spoj#ABA12E. Shooting the balloons!
Shooting the balloons!
Dhinakaran is very fond of games. Shooting the balloons is his favourite. In this game, there are ‘n’ balloons which are arranged in a line. Every balloon has a unique number which is the number of points earned if that balloon is shot. A constraint here is that you should shoot contiguous balloons. So, Dhinakaran wanted to find the maximum number of points he could earn. He sought help from a friend who told him that it was the famous maximum contiguous sum problem. So Dhinakaran learnt about it and was happy. But Dhinakaran is not someone who gets satisfied so easily. He wanted to find the k-th smallest possible contiguous sum! Now, his friend was not able to solve this. So he came to me. I suggested that he approach you. You are a great coder, aren’t you? Help him out.
There will be atleast 1 balloon and atmost 50000 balloons, and each balloon can have atleast 0 point and atmost 109 points.
Input
The first line of each data set contains the number of balloons and value of k.
1 <= k <= (n * (n + 1)) / 2
The second line contains N space separated integers.
Output
The output for each test case should be a single line containing the k-th smallest possible contiguous sum of points that could be achieved.
Example
Input:5 3
1 2 3 4 5
Output:
3
Explanation of sample case:
The first 5 smallest contiguous subsequences are 1, 2, 3, 1 + 2, 4