ABA12E – Shooting the balloons Solution

0
10
SPOJ Solution

ABA12E Statement

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.

ABA12E Solution

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.