QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#412080#8057. Best Carry Player 4ucup-team1716#WA 55ms3676kbC++201.7kb2024-05-16 03:35:242024-05-16 03:35:24

Judging History

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

  • [2024-05-16 03:35:24]
  • 评测
  • 测评结果:WA
  • 用时:55ms
  • 内存:3676kb
  • [2024-05-16 03:35:24]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define pb push_back

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	int t = 1;
	cin >> t;
    while(t-->0)
    {
        int n;
        cin >> n;

        vector<ll> a(n), b(n);
        for(int i=0; i<n; i++) cin >> a[i];
        for(int i=0; i<n; i++) cin >> b[i];

        ll suma = 0, sumb = 0;
        for(int i=0; i<n; i++)
        {
            suma += a[i];
            sumb += b[i];
        }

        if(suma < sumb) a[0] += sumb - suma;
        else b[0] += suma - sumb;

        bool ok = false;
        int index1 = n-1, index2 = 0;
        ll ans = 0;

        vector<ll> p, q(n, 0);

        for(index1 = n-1; index1 >= 0; index1--)
        {
            index2 = max(index2, n - 1 - index1);
            while(index2 != n && a[index1] > 0)
            {
                ll m = min(a[index1], b[index2]);
                //cout << "!! " << m << " " << index1 << "\n";
                if(m > 0) p.pb(index1);
                a[index1] -= m;
                b[index2] -= m;
                ans += m;
                if(index1 + index2 >= n) ok = true;
                if(b[index2] == 0) index2++;
            }
        }

        reverse(p.begin(), p.end());
        int k = p.size(), now = 0;
        ll sum = 0;
        for(int i=0; i<n; i++)
        {
            while(now < k && p[now] == i)
            {
                //cout << "! " << p[now] << " " << sum << "\n";
                if(sum > 0) ok = true;
                now++;
            }
            sum += b[n - 1 - i];
        }

        cout << ans - 1 + ok << "\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 55ms
memory: 3580kb

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

result:

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