CF1279B 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 𝑛 parts. It takes 𝑎𝑖 seconds to recite the 𝑖-th part. Vasya can’t change the order of parts in the verse: firstly he recites the part which takes 𝑎1 seconds, secondly — the part which takes 𝑎2 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 𝑠 seconds. For example, if 𝑠=10, 𝑎=[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 𝑡 test cases.

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

The first line of each test case contains two integers 𝑛 and 𝑠 (1≤𝑛≤105,1≤𝑠≤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 𝑛 integers 𝑎1,𝑎2,…,𝑎𝑛 (1≤𝑎𝑖≤109) — the time it takes to recite each part of the verse.

It is guaranteed that the sum of 𝑛 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.

Example
inputCopy
3
7 11
2 9 1 3 18 1 4
4 35
11 9 10 7
1 8
5
outputCopy
2
1
0
Note
In the first test case if Vasya skips the second part then he gets three gifts.

In the second test case no matter what part of the verse Vasya skips.

In the third test case Vasya can recite the whole verse.

题意: 按顺序取数,但是要花钱,你可以取数的时候使一个免费,求最多能取多少个,全能取的话输出0.
思路: 模拟吧

#include <cstdio>
#include <cstring>
#include <algorithm>
 
using namespace std;
 
typedef long long ll;
ll a[100005];
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        ll s;
        scanf("%d%lld",&n,&s);
        ll sum = 0;
        for(int i = 1;i <= n;i++)
        {
            scanf("%lld",&a[i]);
            sum += a[i];
        }
        
        if(sum <= s)
        {
            printf("0\n");
            continue;
        }
        ll mx = 0,now = 0,ansid = 0,mxid = 0;
        for(int i = 1;i <= n;i++)
        {
            now += a[i];
            if(mx <= a[i])
            {
                mxid = i;
                mx = a[i];
            }
            if(now - mx <= s)
            {
                ansid = mxid;
            }
        }
        printf("%lld\n",ansid);
    }
    return 0;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值