QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#657013 | #8057. Best Carry Player 4 | ucup-team4992# | WA | 44ms | 7760kb | C++20 | 1.5kb | 2024-10-19 14:03:12 | 2024-10-19 14:03: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];
for(int i=0; i<m; i++) cin>>B[i];
ll ans=0;
for(int i=0; i<m; i++){
C[i]=A[i]; D[i]=B[m-1-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=0; 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;
for(int i=1; i<m; i++) if(A[i]){
flag=1;
break;
}
if(flag && D[m-1]){
cout<<ans<<"\n";
return;
}
flag=0;
for(int i=1; i<m; i++) if(B[i]){
flag=1;
break;
}
if(flag && C[m-1]){
cout<<ans<<"\n";
return;
}
cout<<ans-1<<"\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: 7760kb
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: 44ms
memory: 7732kb
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 -1 4 -1 3 3 3 2 -1 -1 1 0 3 0 3 0 0 -1 -1 0 0 0 2 1 4 1 -1 2 3 2 1 4 0 -1 2 0 0 1 1 -1 0 2 5 3 1 2 2 -1 1 2 2 2 -1 3 0 2 0 1 0 0 -1 4 1 1 2 2 0 3 2 -1 1 -1 1 -1 0 1 1 2 0 3 4 0 2 5 -1 1 1 0 0 -1 3 1 3 -1 2 0 4 3 3 0 2 2 1 1 3 1 1 -1 0 -1 1 -1 3 2 1 -1 1 1 1 1 2 -1 0 2 3 1 3 3 2 2 1 -1 2 -1 0 2 3 1...
result:
wrong answer 1st numbers differ - expected: '2', found: '1'