QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#638005 | #8057. Best Carry Player 4 | IllusionaryWhiteTraveler# | WA | 137ms | 5616kb | C++14 | 764b | 2024-10-13 14:36:53 | 2024-10-13 14:36:53 |
Judging History
answer
#include<iostream>
#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;
}
L pre=0;
for(int i=0;i<n;i++){
pre+=b[n-i-1];
L c=min(a[i],pre);
ans+=c;
a[i]-=c;
pre-=c;
}
ans+=min(sa-sb,a[n-1]);
cout<<ans<<endl;
}
int main(){
int t;
cin>>t;
for(int i=0;i<t;i++){
Solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5616kb
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: 137ms
memory: 5616kb
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'