QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#739469 | #8057. Best Carry Player 4 | UESTC_NLNS# | WA | 47ms | 5712kb | C++20 | 1.5kb | 2024-11-12 21:51:18 | 2024-11-12 21:51:19 |
Judging History
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,sa,sb,a[N],b[N];
set<int> s;
bool flag;
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;flag=false;
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;
}
ans=0;
for(int i=0,j=n-1;;)
{
while(j>=0&&!b[j]) j--;
if(j==-1) break;
while(i<n&&(i+j<n-1||(!a[i]))) i++;
if(i==n) break;
tmp=min(a[i],b[j]);
a[i]-=tmp;
b[j]-=tmp;
ans+=tmp;
if(i+j>=n) flag=true;
}
/* if(!flag)
{
ans=1;
a[s1]--;b[s2]--;
for(int i=0,j=n-1;;)
{
while(j>=0&&!b[j]) j--;
if(j==-1) break;
while(i<n&&(i+j<n-1||(!a[i]))) i++;
if(i==n) break;
tmp=min(a[i],b[j]);
a[i]-=tmp;
b[j]-=tmp;
ans+=tmp;
}
}*/
if(!flag) ans--;
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
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5712kb
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: 47ms
memory: 5692kb
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 0 4 0 3 3 3 2 0 0 1 0 2 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 5 3 2 2 1 0 0 2 2 2 0 3 0 2 1 1 0 1 0 4 0 0 2 2 0 3 3 0 2 0 1 0 0 1 1 2 0 3 4 0 2 5 0 1 1 0 0 0 2 1 3 0 1 0 4 3 3 0 2 2 0 1 3 1 1 0 0 0 1 0 3 2 2 0 1 0 1 0 1 0 0 2 4 1 2 3 2 2 2 0 1 0 0 2 3 1 3 0 0 2 2 3 0 1 2 0 1 1 ...
result:
wrong answer 1st numbers differ - expected: '2', found: '1'