QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#349673 | #8057. Best Carry Player 4 | mcpqndq# | WA | 44ms | 3784kb | C++17 | 969b | 2024-03-10 03:53:33 | 2024-03-10 03:53:33 |
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){
ll g=min(r,a[i]);
if(g>0){
bb=true;
a[i]-=g;
x+=g;
}
g=min(b[i],a[i]);
if(i==0){
g=b[i];
}
if(i==m-1){
g=a[i];
}
x+=g;
r+=b[i]-g;
}
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: 0ms
memory: 3784kb
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: 44ms
memory: 3516kb
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:
1 0 4 0 4 3 3 2 0 0 1 0 2 0 3 0 0 0 0 0 0 0 4 0 4 1 0 2 3 2 1 4 0 0 3 0 0 1 1 0 0 3 5 3 1 2 1 0 0 2 2 2 0 3 0 2 1 1 0 0 0 4 0 0 2 2 0 3 3 0 1 0 1 0 0 1 1 2 0 2 4 0 3 5 0 1 1 0 0 0 2 1 3 0 1 0 4 3 3 0 2 2 0 1 3 0 1 0 0 0 1 0 3 2 2 0 1 0 2 0 1 0 0 2 4 1 2 3 2 2 2 0 1 0 0 2 3 1 3 0 0 2 2 3 0 1 1 0 1 1 ...
result:
wrong answer 1st numbers differ - expected: '2', found: '1'