QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#738948 | #8057. Best Carry Player 4 | lixp# | WA | 55ms | 5888kb | C++17 | 1.0kb | 2024-11-12 20:22:24 | 2024-11-12 20:22:44 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=5e5+10;
int a[N],b[N],n;
long long ans;
bool flag;
void solve() {
scanf("%lld",&n);
for(int i=1;i<=n;i++)
scanf("%lld",&a[i]);
for(int i=1;i<=n;i++)
scanf("%lld",&b[i]);
if(n==2) {
if(a[2]+b[2]>=1) cout<<a[2]+b[2]-1<<"\n";
else cout<<"0\n";
return;
}
int sma=0,smb=0;
for(int i=2,j=n-1;i<n;i++,j--) {
int mn=min(a[i],b[j]);
a[i]-=mn,b[j]-=mn; ans+=mn;
if(!flag && a[i] && smb) a[i]--,smb--,ans++,flag=1;
if(!flag && a[i] && b[n]) a[i]--,b[n]--,ans++,flag=1;
mn=min(a[i],smb);
a[i]-=mn; smb-=mn; ans+=mn;
smb+=b[j];
}
if(smb && a[n]) a[n]--,ans++,flag=1;
ans+=a[n]+b[n];
if(flag) cout<<ans<<"\n";
else cout<<ans-1<<"\n";
}
void init() {
flag=false; ans=0;
}
signed main() {
int T;scanf("%lld",&T);
while(T--) {
init(); solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 5860kb
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: 55ms
memory: 5888kb
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 4 3 3 2 -1 -1 1 0 3 0 3 0 0 -1 -1 0 0 0 4 0 4 1 -1 2 4 3 1 5 0 -1 2 0 0 1 1 -1 0 3 5 3 2 2 2 -1 1 2 2 2 -1 4 0 2 0 1 0 1 -1 4 1 1 2 2 -1 3 3 -1 2 -1 1 -1 0 1 1 2 0 3 4 -1 2 5 -1 1 1 0 0 -1 2 1 3 -1 2 0 4 3 3 0 2 2 1 1 3 1 1 -1 0 -1 1 -1 3 2 2 -1 1 1 1 0 1 -1 0 2 4 1 3 3 2 2 2 -1 2 -1 0 2 3...
result:
wrong answer 1st numbers differ - expected: '2', found: '1'