QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#349711 | #8057. Best Carry Player 4 | mcpqndq# | WA | 41ms | 3640kb | C++17 | 1.0kb | 2024-03-10 04:31:19 | 2024-03-10 04:31:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vi;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
ll t;cin>>t;
while(t--){
ll m;cin>>m;
vi a(m);rep(i,0,m)cin>>a[i];
vi b(m);rep(i,0,m)cin>>b[i];
ll z1=0,z2=0;
rep(i,0,m)if(a[i]!=0)z1=i;
rep(i,0,m)if(b[i]!=0)z2=i;
if(z1+z2<m){
cout<<"0\n";
continue;
}
reverse(all(b));
ll x=0;
bool bb=false;
ll r=0;
rep(i,0,m){
bool b2=x>0;
ll g=min(r,a[i]);
if(g>0){
bb=true;
a[i]-=g;
r-=g;
x+=g;
}
g=min(b[i],a[i]);
if(i==0){
g=b[i];
}
if(i==m-1){
g=a[i];
}
a[i]-=g;
x+=g;
r+=b[i]-g;
if(a[i]>0&&b2){
bb=true;
}
}
if(bb){
cout<<x<<"\n";
}else{
cout<<x-1<<"\n";
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3492kb
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: 3640kb
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 4 3 3 2 0 0 1 1 3 0 3 0 0 0 0 0 0 0 4 0 4 1 0 2 4 3 1 5 0 0 2 0 0 1 1 0 0 3 5 3 2 2 2 0 1 2 2 2 0 4 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 5th numbers differ - expected: '3', found: '4'