QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#708148#8057. Best Carry Player 4WolamWA 38ms5768kbC++171.5kb2024-11-03 19:52:082024-11-03 19:52:09

Judging History

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

  • [2024-11-03 19:52:09]
  • 评测
  • 测评结果:WA
  • 用时:38ms
  • 内存:5768kb
  • [2024-11-03 19:52:08]
  • 提交

answer

#include<bits/stdc++.h>
#define endl "\n"
#define int long long
using namespace std;
using ll = long long;
const int maxn = 5e5 + 10;
int n,a[maxn],b[maxn];
void solve(void)
{
    cin>>n;
    int suma=0,sumb=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        suma+=a[i];
    }
    for(int i=0;i<n;i++)
    {
        cin>>b[i];
        sumb+=b[i];
    }
    if(suma>sumb)b[0]+=suma-sumb;
    else a[0]+=sumb-suma;
    int mxa=n-1,mxb=n-1,mia=0,mib=0;
    while(mxa>=0&&!a[mxa])mxa--;
    while(mxb>=0&&!b[mxb])mxb--;
    if(mxa+mxb<n)
    {
        cout<<"0\n";
        return;
    }
    int ans1=0;
    for(int i=0;i<n;i++)
    {
        int t=min(a[i],b[n-i-1]);
        if(t)
        {
            mia=min(i,mia);
            mib=n-i-1;
        }
        ans1+=t;
        a[i]-=t;
        b[n-i-1]-=t;
    }
    int sum=0,ans2=0;
    for(int i=0;i<=n;i++)
    {
        sum+=b[n-i-1];
        int t=min(a[i],sum);
        ans2+=t;
        sum-=t;
    }
    if(ans2)
    {
        cout<<ans1+ans2<<'\n';
        return;
    }
    mxa=mxb=n-1;
    while(mxa>=0&&!a[mxa])mxa--;
    while(mxb>=0&&!b[mxb])mxb--;
    int ans=ans1+ans2;
    if(mxa>mia||mxb>mib)
    {
        cout<<ans<<'\n';
        return;
    }
    cout<<ans-1<<'\n';
}
signed main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}
/*
1
10
0 0 3 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 3 3
*/

詳細信息

Test #1:

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

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: 38ms
memory: 5768kb

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:

2
0
4
0
3
3
3
2
0
0
1
1
3
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
2
0
1
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
2
1
2
0
3
4
0
2
5
0
2
1
0
0
0
3
2
3
0
2
0
4
3
3
0
2
2
0
1
3
1
1
0
0
0
1
0
3
2
2
0
2
1
1
0
2
0
0
2
4
1
3
3
2
2
2
0
2
0
0
2
3
1
3
1
0
2
2
3
0
1
2
0
1
1
...

result:

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