QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#637965 | #8057. Best Carry Player 4 | IllusionaryWhiteTraveler# | WA | 107ms | 5800kb | C++14 | 902b | 2024-10-13 14:29:25 | 2024-10-13 14:29:27 |
Judging History
answer
#include<iostream>
#include<stack>
#include<algorithm>
using namespace std;
#define L long long
#define N 500000
L a[N],b[N];
void Solve(){
int n;
cin>>n;
L ans=0,sa=0,sb=0;
for(int i=0;i<n;i++){
cin>>a[i];
sa+=a[i];
}
for(int i=0;i<n;i++){
cin>>b[i];
sb+=b[i];
}
if(sa<sb){
for(int i=0;i<n;i++){
swap(a[i],b[i]);
}
swap(sa,sb);
}
for(int i=1;i<n;i++){
if(a[i]>0&&b[n-i]>0){
a[i]--;
b[n-i]--;
ans=1;
break;
}
}
if(ans==0){
cout<<0<<endl;
return;
}
b[0]+=sa-sb;
stack<int>S;
for(int i=0;i<n;i++){
if(b[n-i-1]>0){
S.push(n-i-1);
}
while(a[i]>0&&S.empty()==false){
int x=S.top();
L c=min(a[i],b[x]);
ans+=c;
a[i]-=c;
b[x]-=c;
if(b[x]==0){
S.pop();
}
}
}
cout<<ans<<endl;
}
int main(){
int t;
cin>>t;
for(int i=0;i<t;i++){
Solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5636kb
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: 107ms
memory: 5800kb
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 3 0 3 0 3 0 0 0 1 1 3 0 3 0 0 0 0 0 0 0 4 0 4 0 0 2 3 3 0 5 0 0 2 0 0 1 1 0 0 3 5 3 2 2 2 0 1 0 0 2 0 0 0 2 0 1 0 1 0 4 0 0 0 2 0 3 3 0 2 0 0 0 0 1 1 2 0 0 3 0 2 5 0 2 1 0 0 0 3 2 3 0 2 0 4 3 3 0 0 2 0 1 3 1 1 0 0 0 0 0 3 2 0 0 0 0 1 0 1 0 0 0 4 1 0 0 2 0 2 0 2 0 0 0 3 0 3 1 0 2 0 3 0 1 2 0 0 1 ...
result:
wrong answer 3rd numbers differ - expected: '4', found: '3'