QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#625480 | #8057. Best Carry Player 4 | tjf4# | WA | 43ms | 11840kb | C++20 | 1.5kb | 2024-10-09 19:29:07 | 2024-10-09 19:29:07 |
Judging History
answer
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef vector<pii> vii;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<char> vc;
const ll inf=1e18;
const int N=5e5+10;
ll m,a[N],b[N],c[N],as[N],bs[N];
int main() {
IOS
int T;
cin>>T;
while(T--) {
cin>>m; c[m]=0;
ll s1=0,s2=0;
for(int i=0;i<=m+1;i++) a[i]=b[i]=c[i]=as[i]=bs[i]=0;
for(int i=0;i<m;i++) cin>>a[i],s1+=a[i],as[i]=a[i];
for(int i=0;i<m;i++) cin>>b[i],s2+=b[i],bs[i]=b[i];
if(s1>s2) b[0]+=abs(s1-s2),bs[0]=b[0];
else a[0]+=abs(s1-s2),as[0]=a[0];
ll rf=m-1,sum=0,pd=0,fg=0;
for(int i=0;i<m;i++) {
if(rf<0) break;
if(a[i]>0&&b[rf]>0&&i+rf>=m) pd=1;
if(a[i]>0&&b[i]>0) fg++;
if(a[i]==b[rf]) {
sum+=a[i];
a[i]=b[rf]=0;
rf--;
}
else if(a[i]>b[rf]) {
sum+=b[rf];
a[i]-=b[rf];
b[rf]=0;
rf--;
if(i+rf<m-1);
else i--;
}
else if(a[i]<b[rf]) {
sum+=a[i];
b[rf]-=a[i];
}
}
for(int i=0;i<m;i++) a[i]=as[i];
for(int i=0;i<m;i++) b[i]=bs[i];
if(pd) cout<<sum<<'\n';
else if(fg>1) cout<<sum-1<<'\n';
else {
ll mx1=-1,mx2=-1;
for(int i=m-1;i>=0;i--) {
if(a[i]>0&&mx1<0) mx1=i;
if(b[i]>0&&mx2<0) mx2=i;
}
if(mx1>=0&&mx2>=0&&mx1+mx2>=m) pd=1;
if(pd==1) cout<<sum-1<<'\n';
else cout<<0<<'\n';
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 11768kb
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: 43ms
memory: 11840kb
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 3 3 3 2 0 0 1 0 2 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 1 0 0 2 2 2 0 3 0 2 1 1 0 1 0 4 0 0 2 2 0 3 3 0 2 -1 1 0 0 1 1 2 0 3 4 0 2 5 0 1 1 0 0 0 2 1 3 0 1 0 4 3 3 0 2 2 0 1 3 1 1 0 0 0 1 0 3 2 2 0 1 0 1 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 2 0 1 1...
result:
wrong answer 1st numbers differ - expected: '2', found: '1'