QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#767604 | #8057. Best Carry Player 4 | yangjl | WA | 41ms | 3524kb | C++20 | 1.7kb | 2024-11-20 21:24:51 | 2024-11-20 21:24:55 |
Judging History
answer
/**
* author: yangjl
* created: 2024.11.20 20:45:08
**/
#include <bits/stdc++.h>
#ifdef YJL
#include "debug.h"
#else
#define debug(...)0
#endif
using namespace std;
using ll = long long;
template<class T>
istream& operator>>(istream& is, vector<T>& v) {
for(auto& x : v) {
is >> x;
}
return is;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int tt;
cin >> tt;
while(tt--) {
int m;
cin >> m;
vector<int> a(m), b(m);
cin >> a >> b;
ll suma = accumulate(a.begin(), a.end(), 0ll);
ll sumb = accumulate(b.begin(), b.end(), 0ll);
if(suma < sumb) {
swap(suma, sumb);
swap(a, b);
}
bool carryExist = false;
for(int i = 1, j = m - 1; i < m; ++i) {
while(j > 1 and b[j] == 0) {
j--;
}
if(a[i] > 0 and i + j >= m and b[j] > 0) {
a[i] --;
b[j]--;
carryExist = true;
break;
}
}
if(!carryExist) {
cout << "0\n";
continue;
}
ll tmp = min<ll>(suma - sumb, a.back());
a.back() -= tmp;
int ans = tmp + 1;
for(int i = m - 1, j = 0; i >= 0; --i) {
int x = a[i];
while(j < m and i + j < m - 1) {
j++;
}
while(x and j < m) {
int t = min(x, b[j]);
ans += t;
x -= t;
b[j] -= t;
if(b[j] == 0) {
j++;
}
}
}
cout << ans << '\n';
}
return 0;
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3524kb
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: 41ms
memory: 3496kb
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 3 0 3 1 0 2 3 3 1 5 0 0 2 0 0 1 1 0 0 3 4 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 3 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 2 2 2 2 2 0 2 0 0 2 3 1 2 1 0 2 2 2 0 1 2 0 1 1 ...
result:
wrong answer 23rd numbers differ - expected: '4', found: '3'