B. Verse For Santa

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

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;
}
Exception setting up node for Apparel_Pants on Robert: System.ArgumentException: Illegal characters in path. [Ref 67275643] Duplicate stacktrace, see ref for original UnityEngine.StackTraceUtility:ExtractStackTrace () (wrapper dynamic-method) MonoMod.Utils.DynamicMethodDefinition:Verse.Log.Error_Patch3 (string) (wrapper dynamic-method) MonoMod.Utils.DynamicMethodDefinition:Verse.PawnRenderTree.SetupApparelNodes_Patch0 (Verse.PawnRenderTree) (wrapper dynamic-method) MonoMod.Utils.DynamicMethodDefinition:Verse.PawnRenderTree.SetupDynamicNodes_Patch1 (Verse.PawnRenderTree) (wrapper dynamic-method) MonoMod.Utils.DynamicMethodDefinition:Verse.PawnRenderTree.TrySetupGraphIfNeeded_Patch1 (Verse.PawnRenderTree) (wrapper dynamic-method) MonoMod.Utils.DynamicMethodDefinition:Verse.PawnRenderTree.EnsureInitialized_Patch1 (Verse.PawnRenderTree,Verse.PawnRenderFlags) (wrapper dynamic-method) MonoMod.Utils.DynamicMethodDefinition:Verse.PawnRenderer.RenderCache_Patch0 (Verse.PawnRenderer,Verse.Rot4,single,UnityEngine.Vector3,bool,bool,bool,bool,System.Collections.Generic.IReadOnlyDictionary`2<RimWorld.Apparel, UnityEngine.Color>,System.Nullable`1<UnityEngine.Color>,bool) RimWorld.PawnCacheRenderer:OnPostRender () (wrapper dynamic-method) MonoMod.Utils.DynamicMethodDefinition:RimWorld.PawnCacheRenderer.RenderPawn_Patch1 (RimWorld.PawnCacheRenderer,Verse.Pawn,UnityEngine.RenderTexture,UnityEngine.Vector3,single,single,Verse.Rot4,bool,bool,bool,bool,UnityEngine.Vector3,System.Collections.Generic.IReadOnlyDictionary`2<RimWorld.Apparel, UnityEngine.Color>,System.Nullable`1<UnityEngine.Color>,bool) RimWorld.PortraitsCache/PortraitParams:RenderPortrait (Verse.Pawn,UnityEngine.RenderTexture) RimWorld.PortraitsCache:Get (Verse.Pawn,UnityEngine.Vector2,Verse.Rot4,UnityEngine.Vector3,single,bool,bool,bool,bool,System.Collections.Generic.IReadOnlyDictionary`2<RimWorld.Apparel, UnityEngine.Color>,System.Nullable`1<UnityEngine.Color>,bool,System.Nullable`1<Verse.PawnHealthState>) (wrapper dynamic-method) MonoMod.Utils.DynamicMethodDefinition:RimWorld.ColonistBarColonistDrawer.DrawColonist_Patch1 (RimWorld.ColonistBarColonistDrawer,UnityEngine.Rect,Verse.Pawn,Verse.Map,bool,bool) RimWorld.ColonistBar:ColonistBarOnGUI () (wrapper dynamic-method) MonoMod.Utils.DynamicMethodDefinition:RimWorld.MapInterface.MapInterfaceOnGUI_BeforeMainTabs_Patch1 (RimWorld.MapInterface) (wrapper dynamic-method) MonoMod.Utils.DynamicMethodDefinition:RimWorld.UIRoot_Play.UIRootOnGUI_Patch3 (RimWorld.UIRoot_Play) (wrapper dynamic-method) MonoMod.Utils.DynamicMethodDefinition:Verse.Root.OnGUI_Patch2 (Verse.Root)
03-19
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值