re求助
查看原帖
re求助
1287433
__ycy1124__楼主2024/7/13 08:23

不知道为什么re

#include<bits/stdc++.h>
using namespace std;
int a[200001];
void read(int &x){
	int f=1;
	x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-'){
			f=-f;
		}
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x*=10;
		x+=ch-'0';
		ch=getchar();
	}
	x*=f;
}
struct Node{
	int i,w;
};
deque <Node> q;
int main(){
	//freopen("ritsu.in","r",stdin);
	//freopen("ritsu.out","w",stdout);
	int T;
	read(T);
	while(T){
		T--;
		int n;
		read(n);
		int l=1;
		long long int js=0;
		bool bj=0;
		while(!q.empty()){
			q.pop_front();
		}
		for(int i=1;i<=n;i++){
			read(a[i]);
			js+=a[i];
			while(!q.empty()&&q.front().w<=a[i]){
				q.pop_front();
			}
			q.push_front({i,a[i]});
			if(js<=0){
				for(l;l<=i;l++){
					js-=a[l];
					if(q.back().i<=l&&!q.empty()){
						q.pop_back();
					}
					if(!q.empty()&&js>q.back().w){
						//printf("\n%d %d %d %d",l,i,q.back().w,js);
						bj=1;
						break;
					}
				}
				//js-=a[l];
			}
			if(js>q.back().w&&!q.empty()){
				bj=1;
				//printf("\n%d %d %d %d",l,i,q.back().w,js);
				break;
			}
		}
		for(l;l<=n;l++){
			js-=a[l];
			if(q.back().i<=l&&!q.empty()){
				q.pop_back();
			}
			if(!q.empty()&&js>q.back().w){
				bj=1;
				break;
			}
			if(l>=n){
				break;
			}
		}
		if(bj){
			printf("NO\n");
		}
		else{
			printf("YES\n");
		}
	}
	return 0;
}
2024/7/13 08:23
加载中...