QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#682448 | #8057. Best Carry Player 4 | AKALemon | WA | 48ms | 3812kb | C++23 | 2.2kb | 2024-10-27 15:30:16 | 2024-10-27 15:30:16 |
Judging History
answer
#include<bits/stdc++.h>
using i64 = long long;
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr), std::cout.tie(nullptr);
int t;
std::cin >> t;
while (t--) {
int n; std::cin >> n;
std::vector<i64> a(n), b(n);
i64 sa = 0, sb = 0;
for (int i = 0; i < n; i++) std::cin >> a[i], sa += a[i];
for (int i = 0; i < n; i++) std::cin >> b[i], sb += b[i];
if (sa < sb) a[0] += sb - sa;
else b[0] += sa - sb;
i64 ans = 0;
bool ok = true;
int l = 0, r = n - 1;
// for (int i = 0; i < n; i++) {
// if (a[i] && b[n - i - 1]) {
// int d = std::min<i64>(a[i], b[n - i - 1]);
// a[i] -= d;
// b[n - i - 1] -= d;
// ans += d;
// }
// }
// if (ans == 0) {
// std::cout << 0 << "\n";
// continue;
// }
while (l < n) {
while (l < n && !a[l]) l++;
while (r >= 0 && !b[r]) r--;
if (l == n || r == -1) break;
if (l + r + 1 < n) {
l++;
continue;
} else if (l + r + 1 >= n) {
int d = std::min(a[l], b[r]);
a[l] -= d, b[r] -= d;
ans += d;
if (l + r + 1 > n) ok = false;
}
}
// for (int i = 0; i < n; i++) std::cerr << a[i] << " \n"[i == n - 1];
// i64 last = 0;
// while (l < n) {
// while (l < n && !a[l]) l++;
// if (l == n) break;
// if (last) ok = false;
// while (r >= 0 && (l + r + 1) > n) {
// last += b[r--];
// }
// int d = std::min<i64>(a[l], last);
// a[l] -= d, last -= d;
// ans += d;
// // std::cerr << l << ' ' << r << ' ' << d << "\n";
// if (last == 0) l++;
// }
// std::cerr << ans << ' ';
// std::cerr << ok << ' ';
// ans += a[n - 1] + b[n - 1];
std::cout << ans - ok << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3812kb
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: 48ms
memory: 3564kb
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 2 0 3 0 0 -1 -1 0 0 0 4 0 4 1 -1 2 3 3 1 5 0 -1 2 0 0 1 1 -1 0 3 5 3 2 2 1 -1 0 2 2 2 -1 3 0 2 1 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 1 0 4 3 3 0 2 2 1 1 3 1 1 -1 0 -1 1 -1 3 2 2 -1 1 0 1 0 1 -1 0 2 4 1 2 3 2 2 2 -1 1 -1 0 2 3...
result:
wrong answer 1st numbers differ - expected: '2', found: '1'