QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#423881#8057. Best Carry Player 4letongWA 57ms10096kbC++141.6kb2024-05-28 18:47:192024-05-28 18:47:19

Judging History

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

  • [2024-05-28 18:47:19]
  • 评测
  • 测评结果:WA
  • 用时:57ms
  • 内存:10096kb
  • [2024-05-28 18:47:19]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=500100;
int T,m,n1,n2,a[N],b[N],aa[N],bb[N];
ll ans1,ans2;
int main()
{
	scanf("%d",&T);
	while(T--){
		scanf("%d",&m);
		ans1=0;ans2=0;
		for(int i=0;i<m;i++) scanf("%d",&a[i]),n1+=a[i],bb[i]=a[i];
		for(int i=0;i<m;i++) scanf("%d",&b[i]),n2+=b[i],aa[i]=b[i];
		if(n1>n2) b[0]+=n1-n2,aa[0]=b[0];
		else a[0]+=n2-n1,bb[0]=a[0];
		bool flag1=0,flag2=0;
		int mx=m-1;
		for(int i=0;i<m;i++){
			while(a[i]&&mx>=0){
				if(b[mx]==0){
					mx--;
					continue;
				}
				if(mx+i<m-1) break;
				if(mx+i>=m){
					flag1=1;
				//	cout<<"=="<<i<<" "<<mx<<endl;
				}
			//	cout<<"!! "<<i<<" "<<mx<<" "<<a[i]<<" "<<b[mx]<<endl;
				if(b[mx]>a[i]) ans1+=a[i],b[mx]-=a[i],a[i]=0;
				else ans1+=b[mx],a[i]-=b[mx],b[mx]=0,mx--;
			}
		}
	//	cout<<ans1<<endl;
		mx=m-1;
		for(int i=0;i<m;i++){
			while(aa[i]&&mx>=0){
				if(bb[mx]==0){
					mx--;
					continue;
				}
				if(mx+i<m-1) break;
				if(mx+i>=m){
					flag2=1;
				//	cout<<"=="<<i<<" "<<mx<<endl;
				}
			//	cout<<"!! "<<i<<" "<<mx<<" "<<a[i]<<" "<<b[mx]<<endl;
				if(bb[mx]>aa[i]) ans2+=aa[i],bb[mx]-=aa[i],aa[i]=0;
				else ans2+=bb[mx],aa[i]-=bb[mx],bb[mx]=0,mx--;
			}
		}
		if(flag1) printf("%lld\n",ans1);
		else if(flag2) printf("%lld\n",ans2);
		else printf("%lld\n",max(0ll,ans2-1));
		
	}
	return 0;
}
/*
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

1
5
0 1 1 1 1
0 0 1 0 0

*/

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 7980kb

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: 57ms
memory: 10096kb

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
3
3
1
0
0
1
1
3
0
3
0
0
0
0
0
0
0
4
0
4
1
0
2
3
3
1
5
0
0
2
0
0
1
1
0
0
3
3
3
2
2
1
0
1
2
2
2
0
3
0
2
1
1
0
1
0
4
1
1
2
2
0
3
2
0
2
0
1
0
0
1
1
2
0
3
4
0
2
5
0
2
1
0
0
0
3
2
3
0
2
0
4
3
3
0
2
2
0
1
2
1
1
0
0
0
1
0
3
2
1
0
2
1
1
0
1
0
0
1
3
1
3
3
2
2
1
0
2
0
0
2
3
1
3
1
0
1
1
3
0
1
2
0
1
1
...

result:

wrong answer 8th numbers differ - expected: '2', found: '1'