QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#349778#8057. Best Carry Player 4mcpqndq#WA 0ms3836kbC++171.5kb2024-03-10 05:23:242024-03-10 05:23:24

Judging History

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

  • [2024-03-10 05:23:24]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3836kb
  • [2024-03-10 05:23:24]
  • 提交

answer

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vi;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);
	ll t;cin>>t;
	while(t--){
		ll m;cin>>m;
		vi a(m);rep(i,0,m)cin>>a[i];
		vi b(m);rep(i,0,m)cin>>b[i];
		ll z1=0,z2=0;
		rep(i,0,m)if(a[i]!=0)z1=i;
		rep(i,0,m)if(b[i]!=0)z2=i;
		if(z1+z2<m){
			cout<<"0\n";
			continue;
		}

		reverse(all(b));
		ll mx=0;

		ll x=0;
		bool bb=false;
		ll r=0;
		rep(i,0,m){
			bool b2=x>0;
			ll g=min(r,a[i]);
			if(g>0){
				bb=true;
				a[i]-=g;
				r-=g;
				x+=g;
			}
			g=min(b[i],a[i]);
			// if(i==0){
			// 	g=b[i];
			// }
			if(i==m-1){
				g=a[i];
			}
			a[i]-=g;
			x+=g;
			r+=b[i]-g;

			if(a[i]>0&&b2){
				bb=true;
			}
		}

		if(bb){
			mx=max(mx, x);
		}else{
			mx=max(mx, x-1);
		}
		x=0;
		bb=false;
		r=0;
		rep(i,0,m){
			bool b2=x>0;
			ll g=min(r,a[i]);
			if(g>0){
				bb=true;
				a[i]-=g;
				r-=g;
				x+=g;
			}
			g=min(b[i],a[i]);
			if(i==0){
				g=b[i];
			}
			// if(i==m-1){
			// 	g=a[i];
			// }
			a[i]-=g;
			x+=g;
			r+=b[i]-g;

			if(a[i]>0&&b2){
				bb=true;
			}
		}

		if(bb){
			mx=max(mx, x);
		}else{
			mx=max(mx, x-1);
		}

		cout<<mx<<"\n";
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3836kb

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:

3
1
2
467900
29

result:

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