QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#711861#8057. Best Carry Player 4acwing_gza#WA 134ms5740kbC++201.3kb2024-11-05 13:48:082024-11-05 13:48:13

Judging History

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

  • [2024-11-05 13:48:13]
  • 评测
  • 测评结果:WA
  • 用时:134ms
  • 内存:5740kb
  • [2024-11-05 13:48:08]
  • 提交

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];
ll suma,sumb;
map<ll,int> Maa;
void solve()
{
    cin>>m;
    int n=m; suma=sumb=0;
    for(int i=0;i<m;++i) cin>>a[i],suma+=a[i];
    for(int i=0;i<m;++i) cin>>b[i],sumb+=b[i];
    if(suma<sumb) a[0]+=sumb-suma;
    if(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)
    {
        if(!a[i]) continue;
        while(ptr>=0 && !b[ptr]) --ptr;
        if(ptr<0) break;
        if(i+ptr>=m) flag=1;
        while(ptr>=m-1-i && a[i])
        {
            int match=std::min(a[i],b[ptr]);
            // printf("match %d of %d in a and %d in b\n",match,i,ptr);
            ans+=match;
            b[ptr]-=match;
            a[i]-=match;
            if(!b[ptr]) --ptr;
        }
        if(ptr<0) break;
    }
    cout<<(flag2==0?0:(flag==0?ans-1:ans))<<endl;
}
int main()
{
    // ios::sync_with_stdio(0);
    // cin.tie(0); cout.tie(0);
    int t=1;
    cin>>t;
    while(t--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5740kb

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: 134ms
memory: 5672kb

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'