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;
}
Vasya正准备在新年向圣诞老人朗诵一首诗,这首诗由多个部分组成,每个部分需要一定的时间来朗诵。Vasya可以跳过诗中的一部分,但不能超过一次,否则圣诞老人会注意到。目标是在不超过圣诞老人聆听时间限制的情况下,通过合理跳过部分以获得最多的礼物。本问题探讨了如何确定最佳跳过部分的策略。
769

被折叠的 条评论
为什么被折叠?



