QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#423865#8057. Best Carry Player 4letongWA 59ms5956kbC++141017b2024-05-28 18:34:402024-05-28 18:34:41

Judging History

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

  • [2024-05-28 18:34:41]
  • 评测
  • 测评结果:WA
  • 用时:59ms
  • 内存:5956kb
  • [2024-05-28 18:34:40]
  • 提交

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];
ll ans;
int main()
{
	scanf("%d",&T);
	while(T--){
		scanf("%d",&m);
		ans=0;
		for(int i=0;i<m;i++) scanf("%d",&a[i]),n1+=a[i];
		for(int i=0;i<m;i++) scanf("%d",&b[i]),n2+=b[i];
		if(n1>n2) b[0]+=n1-n2;
		else a[0]+=n2-n1;
		bool flag=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){
					flag=1;
				//	cout<<"=="<<i<<" "<<mx<<endl;
				}
			//	cout<<"!! "<<i<<" "<<mx<<" "<<a[i]<<" "<<b[mx]<<endl;
				if(b[mx]>a[i]) ans+=a[i],b[mx]-=a[i],a[i]=0;
				else ans+=b[mx],a[i]-=b[mx],b[mx]=0,mx--;
			}
		}
	//	cout<<ans<<endl;
		if(!flag) ans--;
		printf("%lld\n",ans);
	}
	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

*/

详细

Test #1:

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

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: 59ms
memory: 5956kb

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:

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

result:

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