QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#739387#8057. Best Carry Player 4UESTC_NLNS#WA 0ms9740kbC++202.7kb2024-11-12 21:38:232024-11-12 21:38:28

Judging History

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

  • [2024-11-12 21:38:28]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:9740kb
  • [2024-11-12 21:38:23]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=5e5+5,INF=0x3f3f3f3f;
int T,n,s1,s2,p,tmp;
ll ans,ans1,ans2,sa,sb,a[N],b[N],aa[N],bb[N];
set<int> s;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>T;
	while(T--)
	{
		cin>>n;s.clear();p=INF;sa=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];
		if(sa>sb) b[0]+=sa-sb;
		else a[0]+=sb-sa;
		for(int i=0;i<n;i++) if(b[i]) s.insert(i);
		for(int i=n-1;i>=1;i--)
		{
			if(!a[i]) continue;
			auto it=s.lower_bound(n-i);
			if(it==s.end()) continue;
			tmp=(i+(*it))-n;
			if(tmp<p) p=tmp,s1=i,s2=*it;
		}
		if(p==INF)
		{
			cout<<"0\n";
			continue;
		}
		ans1=1;
		for(int i=0;i<n;i++) aa[i]=a[i],bb[i]=b[i];
		a[s1]--;b[s2]--;
		for(int i=0,j=n-1;;)
		{
			while(j>=0&&!bb[j]) j--;
			if(j==-1) break;
			while(i<n&&(i+j<n-1||(!aa[i]))) i++;
			if(i==n) break;
			tmp=min(aa[i],bb[j]);
			aa[i]-=tmp;
			bb[j]-=tmp;
			ans1+=tmp;
		}
		ans=ans1;
		p=INF;
		for(int i=1;i<n;i++)
		{
			if(!a[i]) continue;
			auto it=s.lower_bound(n-i);
			if(it==s.end()) continue;
			tmp=(i+(*it))-n;
			if(tmp<p) p=tmp,s1=i,s2=*it;
		}
		ans1=1;
		for(int i=0;i<n;i++) aa[i]=a[i],bb[i]=b[i];
		a[s1]--;b[s2]--;
		for(int i=0,j=n-1;;)
		{
			while(j>=0&&!bb[j]) j--;
			if(j==-1) break;
			while(i<n&&(i+j<n-1||(!aa[i]))) i++;
			if(i==n) break;
			tmp=min(aa[i],bb[j]);
			aa[i]-=tmp;
			bb[j]-=tmp;
			ans1+=tmp;
		}
		ans=max(ans,ans1);
		for(int i=n-1;i>=1;i--)
		{
			if(!a[i]) continue;
			auto it=s.lower_bound(n-i);
			if(it==s.end()) continue;
			s1=i;s2=*it;break;
		}
		ans1=1;
		for(int i=0;i<n;i++) aa[i]=a[i],bb[i]=b[i];
		a[s1]--;b[s2]--;
		for(int i=0,j=n-1;;)
		{
			while(j>=0&&!bb[j]) j--;
			if(j==-1) break;
			while(i<n&&(i+j<n-1||(!aa[i]))) i++;
			if(i==n) break;
			tmp=min(aa[i],bb[j]);
			aa[i]-=tmp;
			bb[j]-=tmp;
			ans1+=tmp;
		}
		ans=max(ans,ans1);
		for(int i=1;i<n;i++)
		{
			if(!a[i]) continue;
			auto it=s.lower_bound(n-i);
			if(it==s.end()) continue;
			s1=i;s2=*it;break;
		}
		ans1=1;
		for(int i=0;i<n;i++) aa[i]=a[i],bb[i]=b[i];
		a[s1]--;b[s2]--;
		for(int i=0,j=n-1;;)
		{
			while(j>=0&&!bb[j]) j--;
			if(j==-1) break;
			while(i<n&&(i+j<n-1||(!aa[i]))) i++;
			if(i==n) break;
			tmp=min(aa[i],bb[j]);
			aa[i]-=tmp;
			bb[j]-=tmp;
			ans1+=tmp;
		}
		ans=max(ans,ans1);
		cout<<ans<<"\n";
	}
	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
10
5 3 5 3 2 4 2 4 1 5
9 9 8 2 4 4 3 5 3 0
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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:

7
2
3
467901
30

result:

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