Director and room Alottments
Difficulty: Hard

As we all know rooms have been alloted randomly this time.

Earlier students with same IQ level used to live together. But now students
with different IQ levels live in a distributed way. Some have positive IQ 
and some have negative IQ.

Assume that __single student lives in a single room.__
Now director wants to make a team for coding club. He can only chose a 
continous subset of rooms and select all guys in this chosen subset. Now he 
has to chose the __continous subset__ in such a way so that the sum of IQ 
level of all students in chosen continous subset of rooms is __less than 'K' 
and as close as K as possible__. Output the __maximum IQ sum__ that the 
director can chose.

__INPUT FORMAT__

First line will contain the number of test cases t.<br>
Second line will contain N (total number of rooms) and K(maximum sum IQ level that director can take)<br>
Third line will contain number N numbers 'ai' that will be IQ level of students in ith room<br>

__CONSTRAINTS__

1<=t<=10<br>
1<=N<=100000<br>
-10^15<=K<=10^15<br>
-10^9<=ai<=10^9<br>

__OUTPUT__

Single integer per line denoting the maximum IQ level sum that director can pick according to condition.

__Sample Input__<br>

2<br>
6 8<br>
3 -2 1 3 2 0<br>
8 -3<br>
-1 0 -2 -2 3 4 5 1<br>

__OUTPUT__<br>
7<br>
-4<br>
###Explanation<br>
test case 1:7 because subarray from index 1-5 will contain sum 3+(-2)+1+3+2=7 that 
is less than 8 and and is such that it is maximum among subarray sums less 
than 8


test case 2:-4 because subarray from index 3-4 will contain sum -2+(-2)=-4 
that is less than -3 and and is such that it is maximum among subarray sums 
less than -3




Input Format:

Output Format:

Sample Input:

Sample Output:

Python 3 starter code:


Reference solution (C++):
	#include <iostream>
	#include<stdio.h>
	#include<stdlib.h>
	#include<set>
	using namespace std;
	int main() 
	{
	int i,n;
	long long int maxi=-1e18,k;
	int a[100009];
	
	long long int cum=0;
	int t;
	cin>>t;
	while(t--)
	{
	cin>>n>>k;
	cum=0;
	maxi=-1e18;
	for(i=0;i<n;i++)
	cin>>a[i];
	set<long long int> myset;
    myset.clear();
	myset.insert(0);
	for(i=0;i<n;i++)
	{
		cum=cum+a[i];
		set<long long int>::iterator it;
		it=myset.upper_bound(cum-k);
		if(it!=myset.end())
		{
			long long int val=cum-*it;
			if(val>maxi)
			{
			maxi=val;
			}
		}
		myset.insert(cum);
	}
	if(maxi==-1e18)
	cout<<0<<endl;
	else
	cout<<maxi<<endl;
	}
	return 0;
	}