QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#624451#8057. Best Carry Player 4ucup-team4479#TL 0ms7488kbC++231.5kb2024-10-09 15:52:452024-10-09 15:52:47

Judging History

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

  • [2024-10-09 15:52:47]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:7488kb
  • [2024-10-09 15:52:45]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=500005;
int m;
int a[N],b[N];
void solve()
{
    cin>>m;
    for(int i=0;i<m;i++)
        cin>>a[i];
    for(int i=0;i<m;i++)
        cin>>b[i];
    long long ca=0,cb=0;
    for(int i=0;i<m;i++)
        ca+=a[i],cb+=b[i];
    if(ca<cb) swap(a,b),swap(ca,cb);
    bool has_greater_m=false;
    for(int i=1;i<m;i++)
        if(a[i]>0&&b[m-i]>0)
        {
            has_greater_m=true;
            break;
        }
    if(!has_greater_m)
    {
        cout<<0<<"\n";
        return;
    }
    bool exist_begin=false;
    long long ans=0;
    long long ret=0;
    b[0]+=1e9;
    for(int i=0,j=m-i;i<m;i++)
    {
        int cnt=min(a[i],b[m-1-i]);
        a[i]-=cnt,b[m-1-i]-=cnt;
        if(a[i]>0&&ans>0) exist_begin=true;
        ans+=cnt;
        if(a[i]>0&&ret>0)
        {
            exist_begin=true;
            long long del=min((long long)a[i],ret);
            ans+=del;
            a[i]-=del,ret-=del;
        }
        if(ret>0) exist_begin=true;
        if(b[m-1-i]>0) ret+=b[m-1-i];
    }
    if(!exist_begin)
    {
        ans--;
    }
    cout<<ans<<"\n";
    return;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr),cout.tie(nullptr);
    int T;
    cin>>T;
    while(T--)
        solve();
    return 0;
}

/*
1
2
1 2
3 4

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
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
Time Limit Exceeded

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

result: