QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#771368#8057. Best Carry Player 4Tomorrow#WA 0ms13908kbC++172.5kb2024-11-22 12:13:192024-11-22 12:13:19

Judging History

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

  • [2024-11-22 12:13:19]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:13908kb
  • [2024-11-22 12:13:19]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
i64 m, res;
i64 a[500005];
i64 b[500005];
i64 a1[500005];
i64 b1[500005];
i64 hza[500005];
i64 hzb[500005];
void solve(){
    cin >> m;
    for(int i = 0; i < m; i++){
        cin >> a[i];
        a1[i] = a[i];
    }
    for(int i = 0; i < m; i++){
        cin >> b[i];
        b1[i] = b[i];
    }
    hza[m] = 0;
    hzb[m] = 0;
    for(int i = m - 1; i >= 0; i--){
        hza[i] = hza[i+1] + a[i];
        hzb[i] = hzb[i+1] + b[i];
    }
    /*
    for(int i = 0; i < m; i++){
        cout << hza[i] << ' ';
    }
    cout << endl;
    for(int i = 0; i < m; i++){
        cout << hzb[i] << ' ';
    }
    cout << endl;
    */
    res = 0;
    i64 flag = 1;
    i64 l = 0;
    i64 flag2 = 0;
    for(i64 i = m - 1; i >= 0; i--){
        while(l < m){
            if(l < (m - 1 - i)){
                l++;
                continue;
            }
            if(b1[l] < a1[i]){
                if(l + i >= m && a1[i] > 0 && b1[l] > 0){
                    flag = 0;
                }
                a1[i] -= b1[l];
                res += b1[l];
                b1[l] = 0;
                l++;
                continue;
            }
            if(l + i >= m && a1[i] > 0 && b1[l] > 0){
                flag = 0;
            }
            b1[l] -= a1[i];
            res += a1[i];
            a1[i] = 0;
            break;
        }
    }
    res += b1[m-1];
    b1[m-1] = 0;
    res += a1[m-1];
    a1[m-1] = 0;
    /*
    for(int i = 0; i < m; i++){
        cout << a1[i] << ' ';
    }
    cout << endl;
    for(int i = 0; i < m; i++){
        cout << b1[i] << ' ';
    }
    cout << endl;
    */
    for(int i = 1; i < m; i++){
        if(b[i] <= 0){
            continue;
        }
        if(hza[m - i] >= 0){
            flag2 = 1;
        }
    }
    for(int i = 1; i < m; i++){
        if(a[i] <= 0){
            continue;
        }
        if(hzb[m - i] >= 0){
            flag2 = 1;
        }
    }
    if(flag2 == 0){
        cout << 0 << endl;
        return;
    }
    //cout << res << endl;
    //cout << flag << endl;
    res -= flag;
    res = max(0ll, res);
    cout << res << endl;
    
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    if(fopen("test.in","r"))
    {
        freopen("test.in","r",stdin);
        freopen("test.out","w",stdout);
    }
    i64 tt = 1;
    cin >> tt;
    while(tt--){
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 13908kb

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
1
467899
28

result:

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