QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#657299#8057. Best Carry Player 4ucup-team4992#WA 41ms7776kbC++201.7kb2024-10-19 14:32:082024-10-19 14:32:22

Judging History

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

  • [2024-10-19 14:32:22]
  • 评测
  • 测评结果:WA
  • 用时:41ms
  • 内存:7776kb
  • [2024-10-19 14:32:08]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;

const int M=2e5+5;
ll A[M],B[M],C[M],D[M];
int m;

void solve(){
    cin>>m;
    for(int i=0; i<m; i++) cin>>A[i],C[i]=A[i];
    for(int i=0; i<m; i++) cin>>B[i],D[i]=B[i];
    A[m]=B[m]=C[m]=D[m]=0;
    ll ans=0;
    for(int i=0; i<m; i++){
        ll a=A[i],b=B[m-1-i];
        if(i==0) a=2e9;
        if(i==m-1) b=2e9;
        // cout<<"i = "<<i<<" , a = "<<a<<" , m-1-i = "<<m-1-i<<" , b = "<<b<<"\n";
        ll res=min(a,b);
        A[i]-=res; B[m-1-i]-=res;
        ans+=res;
    }
    bool flag=0,can=0;
    for(int i=1; i<m; i++){
        flag|=(B[m-i]>0);
        if(flag && A[i]>0){
            can=1;
            break;
        }
    }
    if(can){
        ll tot=0;
        for(int i=1; i<m; i++){
            tot+=B[m-i];
            ll res=min(tot,A[i]);
            tot-=res;
            ans+=res;
        }
        cout<<ans<<"\n";
    }else{
        flag=0,can=0;
        for(int i=1; i<m; i++){
            flag|=(B[m-i]>0);
            if(flag && C[i]>0){
                can=1;
                break;
            }
        }
        if(can){
            cout<<ans<<"\n";
            return;
        }
        flag=0,can=0;
        for(int i=1; i<m; i++){
            flag|=(A[m-i]>0);
            if(flag && D[i]>0){
                can=1;
                break;
            }
        }
        if(can){
            cout<<ans<<"\n";
            return;
        }
        cout<<max(ans-1,0ll)<<"\n";
    }
    return;
}


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: 100
Accepted
time: 0ms
memory: 7656kb

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: 41ms
memory: 7776kb

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

result:

wrong answer 5th numbers differ - expected: '3', found: '4'