本文主要是介绍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;
}
这篇关于CF1279B B. Verse For Santa的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!