CF B. Verse For Santa

题目链接
题意:有n个篇文章,每篇文章都有一定的朗诵时间 a [ i ] a[i] ,然后圣诞老人只会听 S S 的时间,然后你可以删除一篇文章使得圣诞老人可以听很多的文章,问是哪篇文章,如果不用删除的话输出 0 0
思路:
脑抽了。。。
肯定是选已经阅读的最大时间的文章,这没错。然后注意判断时的细节。

#include<bits/stdc++.h>
using namespace std;
#define ll long long

const int N = 1e5 + 1000;
ll a[N];
int main(){
	int t;
	ll s;
	int n;
	cin>>t;
	while(t--){
		scanf("%d%lld",&n,&s);
		for(int i = 1;i <= n;++i){
			scanf("%lld",&a[i]);
		}
		int id = 1;
		ll sum = 0;
		int i;
		for( i = 1;i <= n;++i){
			sum += a[i];
			if(a[id] < a[i]) id = i;
			if(sum > s) break;
			
		}
		if(i > n) puts("0");
		else {
			if(sum - a[id] + a[i+1] <= s) cout<<id<<endl;
			else puts("0");
		}
		
	}
}
发布了632 篇原创文章 · 获赞 27 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/qq_43408238/article/details/103752823