QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#330178 | #8057. Best Carry Player 4 | ucup-team2279# | WA | 18ms | 3960kb | C++20 | 1.3kb | 2024-02-17 13:26:47 | 2024-02-17 13:26:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mk make_pair
#define lowbit(x) (x&(-x))
#define pb emplace_back
#define pr pair<int,int>
#define let const auto
#define all(A) A.begin(),A.end()
const int N=5e5+5;
int read(){
int x=0,f=1; char c=getchar();
while(('0'>c||c>'9')&&c!='-') c=getchar();
if(c=='-') f=0,c=getchar();
while('0'<=c&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return f?x:-x;
}
void solve(){
int m=read();
vector <int> a(m),b(m);
for(auto &o:a) o=read();
for(auto &o:b) o=read();
int posa=0,posb=m-1;
ll ans=0,ans2=0;
ll sa=accumulate(all(a),0ll),sb=accumulate(all(b),0ll);
if(sa<sb) a[0]+=sb-sa;
else b[0]+=sa-sb;
int lasa=m-1,lasb=m-1;
while(lasa>0&&!a[lasa]) lasa--;
while(lasb>0&&!b[lasb]) lasb--;
if(lasa+lasb<m) return puts("0"),void();
int p=0,yes=0;
while(posa<m&&posb>=0){
int cur=min(a[posa],b[posb]);
if(posa+posb>=m) ans+=cur;
else if(posa+posb==m-1) ans2+=cur;
else{
if(a[posa]>0&&posa>p) yes=1;
posa++;
continue;
}
if(cur>0) p=posa;
a[posa]-=cur,b[posb]-=cur;
if(!a[posa]) posa++;
if(!b[posb]) posb--;
}
if(posa<m&&*max_element(a.begin()+posa+1,a.end())>0) yes=1;
if(ans) yes=1;
printf("%lld\n",ans+ans2-(!yes));
}
int main(){
int T=read();
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3720kb
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: 18ms
memory: 3960kb
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 1 1 1 0 2 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 117th numbers differ - expected: '2', found: '1'