QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#693167 | #8057. Best Carry Player 4 | SSAABBEERR | WA | 45ms | 5736kb | C++20 | 1.8kb | 2024-10-31 15:39:09 | 2024-10-31 15:39:31 |
Judging History
answer
#include<bits/stdc++.h>
#define lowbit(x) (x & (-x))
#define endl "\n"
#define ll long long
#define int long long
using namespace std;
#define pii pair<int, int>
#define rep(i, a, b) for(int i = a; i <= b; i ++ )
#define pre(i, a, b) for(int i = a; i >= b; i -- )
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int N = 1e6 + 10;
int n, m, k;
int a[N], b[N];
void solve()
{
cin >> n;
int s1 = 0, s2 = 0;
rep(i, 0, n - 1) cin >> a[i], s1 += a[i];
rep(i, 0, n - 1) cin >> b[i], s2 += b[i];
if(s1 < s2) a[0] += (s2 - s1);
else b[0] += (s1 - s2);
int ma1 = 0, ma2 = 0;
rep(i, 0, n - 1)
{
if(a[i]) ma1 = i;
if(b[i]) ma2 = i;
}
if(ma1 + ma2 < n)
{
cout << 0 << endl;
return;
}
int r = n - 1, cnt = 0, f = 0;
vector<int>v;
rep(i, 0, n - 1)
{
if(!a[i]) continue;
if(i + r < n - 1) continue;
if(r >= 0 && !b[r]) r -- ;
while(a[i] && r >= 0 && i + r >= n - 1)
{
if(r + i >= n && b[r])
{
f = 1;
}
if(b[r] <= a[i]) a[i] -= b[r], cnt += b[r], r -- , v.push_back(i);
else
{
cnt += a[i];
b[r] -= a[i];
a[i] = 0;
v.push_back(i);
}
}
}
vector<int>st;
rep(i, 0, n - 1)
{
if(a[i]) st.push_back(i);
}
v.erase(unique(v.begin(), v.end()), v.end());
for(auto it : v)
{
auto itt = upper_bound(st.begin(), st.end(), it);
if(itt != st.end()) f = 1;
}
if(f) cout << cnt << endl;
else cout << cnt - 1 << endl;
}
signed main()
{
IOS;
int _;
_ = 1;
cin >> _;
while(_ -- )
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5664kb
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: 45ms
memory: 5736kb
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 329th numbers differ - expected: '1', found: '2'