QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#355054 | #8057. Best Carry Player 4 | foreverlasting# | WA | 47ms | 3772kb | C++20 | 1.5kb | 2024-03-16 11:46:46 | 2024-03-16 11:46:46 |
Judging History
answer
#include <bits/stdc++.h>
using LL = long long;
using ld = long double;
using Pair = std::pair<int, ld>;
#define inf 1'000'000'000
void solve(const int &Case) {
int m;
std::cin >> m;
std::vector<LL> a(m), b(m);
int mx = 0;
for (auto &x: a)std::cin >> x;
for (auto &x: b)std::cin >> x;
LL P1 = std::accumulate(a.begin(), a.end(), 0ll);
LL P2 = std::accumulate(b.begin(), b.end(), 0ll);
if (P1 > P2)b[0] += P1 - P2;
else a[0] += P2 - P1;
for (int i = 0; i < m; i++) {
if (a[i] > 0)mx = i;
}
for (int i = m - 1; i >= 0; i--) {
if (b[i] > 0) {
if (i + mx < m) {
std::cout << 0 << '\n';
return;
}
else break;
}
}
LL ans = 0;
int fl = 1;
int r = m - 1, l = 0;
while (r >= 0 && l < m) {
while (l + r < m - 1) {
if (b[l] > 0 && mx + l >= m)fl = 0;
l++;
}
if (a[r] > 0 && b[l] > 0 && l + r >= m)fl = 0;
if (a[r] > b[l]) {
a[r] -= b[l];
ans += b[l], l++;
}
else if (a[r] < b[l]) {
b[l] -= a[r];
ans += a[r], r--;
}
else {
ans += b[l], r--, l++;
}
}
ans -= fl;
std::cout << ans << '\n';
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
int T = 1;
std::cin >> T;
for (int Case = 1; Case <= T; Case++)solve(Case);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3472kb
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: 47ms
memory: 3772kb
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 2 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 1 1 0 1 0 0 2 4 1 3 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 248th numbers differ - expected: '0', found: '-1'