B. Verse For Santa

New Year is coming! Vasya has prepared a New Year’s verse and wants to recite it in front of Santa Claus.

Vasya’s verse contains n parts. It takes ai seconds to recite the i-th part. Vasya can’t change the order of parts in the verse: firstly he recites the part which takes a1 seconds, secondly — the part which takes a2 seconds, and so on. After reciting the verse, Vasya will get the number of presents equal to the number of parts he fully recited.

Vasya can skip at most one part of the verse while reciting it (if he skips more than one part, then Santa will definitely notice it).

Santa will listen to Vasya’s verse for no more than s seconds. For example, if s=10, a=[100,9,1,1], and Vasya skips the first part of verse, then he gets two presents.

Note that it is possible to recite the whole verse (if there is enough time).

Determine which part Vasya needs to skip to obtain the maximum possible number of gifts. If Vasya shouldn’t skip anything, print 0. If there are multiple answers, print any of them.

You have to process t test cases.

Input
The first line contains one integer t (1≤t≤100) — the number of test cases.

The first line of each test case contains two integers n and s (1≤n≤105,1≤s≤109) — the number of parts in the verse and the maximum number of seconds Santa will listen to Vasya, respectively.

The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109) — the time it takes to recite each part of the verse.

It is guaranteed that the sum of n over all test cases does not exceed 105.

Output
For each test case print one integer — the number of the part that Vasya needs to skip to obtain the maximum number of gifts. If Vasya shouldn’t skip any parts, print 0.

#include<iostream>
using namespace std;
int main()
{
	int a[100010] , s, t, n, i;
	cin >> t;
	while (t--)
	{
		cin >> n >> s;
		for (i = 1; i <= n; i++)
		{
			cin >> a[i];
		}
		int sum = 0, temp = 1;
		for (i = 1; i <= n; i++)
		{
			sum += a[i];
			if (a[i] > a[temp])
			{
				temp = i;
			}
			if (sum > s)
				break;
		}
		if (i > n)cout << "0" << endl;
		else
		{
			cout << temp << endl;
		}
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值