QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#657217 | #8057. Best Carry Player 4 | ucup-team4992# | WA | 40ms | 7712kb | C++20 | 1.7kb | 2024-10-19 14:23:12 | 2024-10-19 14:23:12 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int M=2e5+5;
ll A[M],B[M],C[M],D[M];
int m;
void solve(){
cin>>m;
for(int i=0; i<m; i++) cin>>A[i],C[i]=A[i];
for(int i=0; i<m; i++) cin>>B[i],D[i]=B[i];
ll ans=0;
for(int i=0; i<m; i++){
ll a=A[i],b=B[m-1-i];
if(i==0) a=2e9;
if(i==m-1) b=2e9;
// cout<<"i = "<<i<<" , a = "<<a<<" , m-1-i = "<<m-1-i<<" , b = "<<b<<"\n";
ll res=min(a,b);
A[i]-=res; B[m-1-i]-=res;
ans+=res;
}
bool flag=0,can=0;
for(int i=1; i<m; i++){
flag|=(B[m-i]>0);
if(flag && A[i]>0){
can=1;
break;
}
}
if(can){
ll tot=0;
for(int i=0; i<m; i++){
tot+=B[m-i];
ll res=min(tot,A[i]);
tot-=res;
ans+=res;
}
cout<<ans<<"\n";
}else{
flag=0,can=0;
for(int i=1; i<m; i++){
flag|=(B[m-i]>0);
if(flag && C[i]>0){
can=1;
break;
}
}
if(can){
cout<<ans<<"\n";
return;
}
flag=0,can=0;
for(int i=1; i<m; i++){
flag|=(A[m-i]>0);
if(flag && D[i]>0){
can=1;
break;
}
}
if(can){
cout<<ans<<"\n";
return;
}
cout<<max(ans-1,0ll)<<"\n";
}
return;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int T=1;
cin>>T;
while(T--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7684kb
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: 40ms
memory: 7712kb
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 2 0 4 1 0 2 4 3 1 5 0 0 2 0 0 1 1 0 0 2 5 3 2 2 2 0 1 2 2 2 0 4 0 2 1 1 0 1 0 4 1 1 2 2 0 3 2 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 1 1 3 1 1 0 0 0 1 0 3 2 1 0 2 1 1 0 1 0 0 2 3 1 3 3 2 2 1 0 2 0 0 2 3 1 3 1 0 2 1 3 0 1 2 1 1 1 ...
result:
wrong answer 23rd numbers differ - expected: '4', found: '2'