QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#638189#8057. Best Carry Player 4IllusionaryWhiteTraveler#WA 115ms5744kbC++14977b2024-10-13 15:09:332024-10-13 15:09:34

Judging History

你现在查看的是最新测评结果

  • [2024-10-13 15:09:34]
  • 评测
  • 测评结果:WA
  • 用时:115ms
  • 内存:5744kb
  • [2024-10-13 15:09:33]
  • 提交

answer

#include<iostream>
#include<algorithm>
using namespace std;
#define L long long
#define N 500000
L a[N],b[N];
void Solve(){
	int n;
	cin>>n;
	L ans=0,sa=0,sb=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sa+=a[i];
	}
	for(int i=0;i<n;i++){
		cin>>b[i];
		sb+=b[i];
	}
	bool tag=false;
	for(int i=1;i<n;i++){
		if(a[i]>0&&b[n-i]>0){
			tag=true;
			break;
		}
	}
	if(tag==false){
		cout<<0<<endl;
		return;
	}
	if(sa<sb){
		for(int i=0;i<n;i++){
			swap(a[i],b[i]);
		}
		swap(sa,sb);
	}
	b[0]+=sa-sb;
	L pre=0;
	int lf=-1;
	for(int i=0;i<n;i++){
		if(a[i]>0&&pre>0){
			tag=false;
		}
		pre+=b[n-i-1];
		L c=min(a[i],pre);
		if(c>0&&lf==-1){
			lf=i;
		}
		ans+=c;
		a[i]-=c;
		pre-=c;
	}
	if(tag==true){
		for(int i=lf+1;i<n;i++){
			if(a[i]>0){
				tag=false;
				break;
			}
		}
	}
	if(tag==true){
		ans--;
	}
	cout<<ans<<endl;
}
int main(){
	int t;
	cin>>t;
	for(int i=0;i<t;i++){
		Solve();
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 5736kb

input:

5
2
1 2
3 4
3
1 0 1
0 1 0
4
1 0 0 1
1 1 1 1
5
123456 114514 1919810 233333 234567
20050815 998244353 0 0 0
10
5 3 5 3 2 4 2 4 1 5
9 9 8 2 4 4 3 5 3 0

output:

5
1
2
467900
29

result:

ok 5 number(s): "5 1 2 467900 29"

Test #2:

score: -100
Wrong Answer
time: 115ms
memory: 5744kb

input:

100000
5
0 1 1 1 1
0 0 1 0 0
5
0 0 0 0 0
1 1 1 0 0
5
0 0 2 1 1
0 2 1 0 1
5
0 0 0 0 0
1 2 1 0 0
5
0 1 0 1 1
0 0 1 1 1
5
2 0 0 0 1
1 0 0 0 3
5
2 0 0 1 1
0 2 1 1 1
5
0 0 0 0 2
0 0 0 0 1
5
0 0 0 0 0
0 1 1 0 0
5
4 0 0 0 0
0 0 0 1 0
5
0 0 0 0 1
2 1 1 0 0
5
0 2 3 0 0
0 0 0 1 0
5
1 1 1 0 1
1 0 1 0 1
5
0 0 0...

output:

2
0
4
0
3
0
3
0
0
0
1
1
3
0
3
0
0
0
0
0
0
0
4
0
4
0
0
2
3
3
0
5
0
0
2
0
0
1
1
0
0
3
5
3
2
2
2
0
1
0
0
2
0
0
0
2
0
1
0
1
0
4
0
0
0
2
0
3
3
0
2
0
0
0
0
1
1
2
0
0
4
0
2
5
0
2
1
0
0
0
3
2
3
0
2
0
4
3
3
0
0
2
0
1
3
1
1
0
0
0
0
0
3
2
0
0
0
0
1
0
1
0
0
0
4
1
0
0
2
0
2
0
2
0
0
0
3
0
3
1
0
2
0
3
0
1
2
0
0
1
...

result:

wrong answer 6th numbers differ - expected: '3', found: '0'