QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#711959 | #8057. Best Carry Player 4 | acwing_gza# | WA | 1ms | 9840kb | C++20 | 1.6kb | 2024-11-05 14:08:04 | 2024-11-05 14:08:05 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef ll i64;
typedef __int128 i128;
constexpr int maxn=5e5+9;
int m;
i64 a[maxn],b[maxn];
i64 ta[maxn],tb[maxn];
ll suma,sumb;
void solve()
{
cin>>m;
int n=m; suma=sumb=0;
for(int i=0;i<m;++i) cin>>a[i],suma+=ta[i]=a[i];
for(int i=0;i<m;++i) cin>>b[i],sumb+=tb[i]=b[i];
// printf("suma=%lld sumb=%lld\n",suma,sumb);
if(suma>sumb)
{
for(int i=0;i<m;++i) swap(a[i],b[i]);
swap(suma,sumb);
}
b[0]+=suma-sumb;
int ptr=m-1;
ll ans=0;
int flag=0,flag2=0;
ll ss=0;
for(int i=0;i<m;++i)
{
ss+=b[m-i];
if(ss && a[i]) { flag2=1; break; }
}
for(int i=0;i<m;++i)
{
while(ptr>=0 && i+ptr>=m-1 && a[i]>=b[ptr])
{
// printf("match %lld of %d in a and %d in b\n",b[ptr],i,ptr);
if(i+ptr>=m) flag=1;
ans+=b[ptr];
a[i]-=b[ptr]; b[ptr]=0;
--ptr;
}
if(ptr>=0 && i+ptr>=m-1 && a[i])
{
// printf("match %lld of %d in a and %d in b\n",a[i],i,ptr);
if(i+ptr>=m) flag=1;
ans+=a[i];
b[ptr]-=a[i]; a[i]=0;
}
}
int tmp=-1;
for(int i=0;i<m;++i)
if(ta[i]>a[i]) {
tmp=i;
break;
}
for(int i=tmp+1;i<m;++i)
if(a[i]) flag=1;
cout<<(flag?ans:(flag2==0?0:ans-1))<<endl;
}
int main()
{
// ios::sync_with_stdio(0);
// cin.tie(0); cout.tie(0);
int t=1;
cin>>t;
while(t--) solve();
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 9840kb
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'