QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#738922#8057. Best Carry Player 4shengZzzWA 60ms5848kbC++201.0kb2024-11-12 20:15:542024-11-12 20:15:54

Judging History

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

  • [2024-11-12 20:15:54]
  • 评测
  • 测评结果:WA
  • 用时:60ms
  • 内存:5848kb
  • [2024-11-12 20:15:54]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=5e5+10;
int a[N],b[N],n;
long long ans;
bool flag;
void solve() {
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
        scanf("%lld",&a[i]);
    for(int i=1;i<=n;i++)
        scanf("%lld",&b[i]);
    if(n==2) {
        if(a[2]+b[2]>=1) cout<<a[2]+b[2]-1<<"\n";
        else cout<<"0\n";
        return;
    }
    int sma=0,smb=0;
    for(int i=2,j=n-1;i<n;i++,j--) {
        int mn=min(a[i],b[j]);
        a[i]-=mn,b[j]-=mn; ans+=mn;
        smb+=b[j];

        if(a[i] && smb) flag=1;

        mn=min(a[i],smb);
        a[i]-=mn; smb-=mn; ans+=mn;
        if(!flag && a[i] && b[n]) b[n]--,a[i]--,flag=1,ans++;
        if(!flag && smb && a[n]) a[n]--,smb--,flag=1,ans++;
    }
    ans+=a[n]+b[n];
    if(flag) cout<<ans<<"\n";
    else cout<<ans-1<<"\n";
}
void init() {
    flag=false; ans=0;
}
signed main() {
    int T;scanf("%lld",&T);
    while(T--) {
        init(); solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 60ms
memory: 5848kb

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

result:

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