QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#739565 | #8057. Best Carry Player 4 | UESTC_NLNS# | WA | 50ms | 5696kb | C++17 | 1.9kb | 2024-11-12 22:12:23 | 2024-11-12 22:12:25 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 5e5 + 5, INF = 0x3f3f3f3f;
int T, n, s1, s2, p, tmp;
ll ans, sa, sb, a[N], b[N];
set<int> s;
bool flag;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> T;
while (T--) {
ll mn = 1e9;
cin >> n;
s.clear();
p = INF;
sa = sb = 0;
flag = false;
for (int i = 0; i < n; i++) cin >> a[i], sa += a[i];
for (int i = 0; i < n; i++) cin >> b[i], sb += b[i];
for (int i = 0; i < n; i++) {
if (a[i]) {
mn = i;
break;
}
}
if (sa > sb)
b[0] += sa - sb;
else
a[0] += sb - sa;
for (int i = 0; i < n; i++)
if (b[i]) s.insert(i);
int mxb = 0;
int mxa = 0;
for (int i = 0; i < n; ++i) {
if (b[i]) mxb = i;
if (a[i]) mxa = i;
}
if (mxa + mxb < n) {
cout << "0\n";
continue;
}
ans = 0;
for (int i = 0, j = n - 1;;) {
while (j >= 0 && !b[j]) j--;
if (j == -1) break;
while (i < n && (i + j < n - 1 || (!a[i]))) i++;
if (i == n) break;
tmp = min(a[i], b[j]);
a[i] -= tmp;
b[j] -= tmp;
ans += tmp;
if (i + j >= n) flag = true;
}
for (int i = mn + 1; i < n; ++i) {
if (a[i]) flag = 1;
}
if (!flag) ans--;
cout << ans << "\n";
// cout << "mn " << mn << '\n';
}
return 0;
}
/*
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
1
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: 1ms
memory: 5636kb
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: 50ms
memory: 5696kb
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 3 3 2 0 0 1 1 3 0 3 0 0 0 0 0 0 0 4 0 4 1 0 2 3 3 1 5 0 0 2 0 0 1 1 0 0 3 5 3 2 2 1 0 1 2 2 2 0 3 0 2 1 1 0 1 0 4 0 0 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 0 1 3 1 1 0 0 0 1 0 3 2 2 0 2 0 1 0 2 0 0 2 4 1 2 3 2 2 2 0 2 0 0 2 3 1 3 1 0 2 2 3 0 1 2 0 1 1 ...
result:
wrong answer 47th numbers differ - expected: '2', found: '1'