QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#350480 | #8057. Best Carry Player 4 | PPP# | WA | 51ms | 3848kb | C++14 | 1.4kb | 2024-03-10 19:22:36 | 2024-03-10 19:22:36 |
Judging History
answer
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define X first
#define Y second
const ll mod = 1000000007;
//const ll mod = 998244353;
void solve()
{
ll n;
cin >> n;
vector<ll> a(n), b(n);
for (ll i=0;i<n;i++) cin >> a[i];
for (ll i=0;i<n;i++) cin >> b[i];
ll Sa = 0, Sb = 0;
for (ll i=0;i<n;i++)
{
Sa += a[i];
Sb += b[i];
}
if (Sa>Sb) b[0] += Sa-Sb;
else a[0] += Sb-Sa;
vector<ll> a0 = a, b0 = b;
ll A = 0;
ll mxi = -1, mxj = -1, ok = 0;
for (ll i=0,j=n-1;i<n;i++)
{
while (a[i]>0 and j>=0 and i+j>=n-1)
{
if (b[j]==0)
{
j--;
continue;
}
ll D = min(a[i],b[j]);
a[i] -= D, b[j] -= D;
A += D;
if (i+j>=n) ok = 1;
}
}
if (ok==1)
{
cout << A << "\n";
return;
}
if (A==0)
{
cout << 0 << "\n";
return;
}
ll mni = mod;
for (ll w=0;w<n;w++)
{
if (a[w]>0) mxi = max(w,mxi);
if (a0[w]>a[w]) mni = min(w,mni);
}
if (mni<mxi) A++;
cout << A-1 << "\n";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
ll T;
T = 1;
cin >> T;
while (T--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3760kb
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: 51ms
memory: 3848kb
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 1 1 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 1 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 1 1 1 ...
result:
wrong answer 63rd numbers differ - expected: '0', found: '1'