CF1279B B. Verse For Santa

2024-04-16 02:08
文章标签 santa cf1279b verse

本文主要是介绍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的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/907531

相关文章

Good Bye 2014 D. New Year Santa Network 树形dp

D. New Year Santa Network time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output New Year is coming in Tree World! In this w

《AI创作类工具之十四——​ Verse》

一.简介 官网:Verse - 新一代生产力工具 Verse是一款功能丰富的智能写作工具,它集合了实时预览、代码高亮、表格编辑和数学公式支持等特色功能,为用户提供了高效的文档编写和管理体验。Verse不仅界面设计简洁,使用户能够更专注于文档内容,还提供了丰富的功能来帮助用户更好地进行Markdown文档的编写和管理。 Verse的一个显著特点是其高度的可定制性。用户可以通过设置菜单来自

OJ 4110 圣诞老人的礼物-Santa Clau’s Gifts__贪心

描述 圣诞节来临了,在城市A中圣诞老人准备分发糖果,现在有多箱不同的糖果,每箱糖果有自己的价值和重量,每箱糖果都可以拆分成任意散装组合带走。圣诞老人的驯鹿最多只能承受一定重量的糖果,请问圣诞老人最多能带走多大价值的糖果。 输入 第一行由两个部分组成,分别为糖果箱数正整数n(1 <= n <= 100),驯鹿能承受的最大重量正整数w(0 < w < 10000),两个数用空格隔开。其余n行每行

week6 常见数据规划-Santa服务调度

规划问题 常见规划问题 线性规划是运筹学的一个重要分支,广泛应用于军事作战、经济分析、经营管理和工程技术等方面。为合理地利用有限的人力、物力、财力等资源作出的最优决策,提供科学的依据。 LP:Linear Programming 线性规划 研究线性约束条件下线性目标函数的极值问题 ILP:Integer Linear Programming 整数线性规划 全部决策变量必须为整

【Codeforces Round #389】Codeforces 752C Santa Claus and Robot

Santa Claus has Robot which lives on the infinite grid and can move along its lines. He can also, having a sequence of m points p1, p2, …, pm with integer coordinates, do the following: denote its

遗传算法(Genetic Algorithm)之deap学习笔记(五):Santa Fe Ant Trail问题

Santa Fe Ant Trail问题是一个经典的人工生命(Artificial Life)问题,用来探索生物群体行为和分布式智能的原理。这个问题是基于蚂蚁在寻找食物时的行为而建立的。问题中,蚂蚁在一个网格世界中寻找食物,并在回家时留下一条路径素,用于引导其他蚂蚁找到食物。蚂蚁在寻找食物和回家时,根据自身和周围信息做出决策,例如嗅觉、视觉等。 Santa Fe Ant Trail问题中,蚂蚁的