QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#738904#8057. Best Carry Player 4lixp#TL 0ms0kbC++171.0kb2024-11-12 20:12:122024-11-12 20:12:27

Judging History

你现在查看的是最新测评结果

  • [2024-11-12 20:12:27]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-11-12 20:12:12]
  • 提交

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;
        smb+=b[j];

        if(a[i] && smb) flag=1;

        mn=min(a[i],smb);
        a[i]-=mn; smb-=mn; ans+=mn;
        if(!flag && a[i] && b[n]) b[n]--,a[i]--,flag=1,ans++;
        if(!flag && smb && a[n]) a[n]--,smb--,flag=1,ans++;
    }
    ans+=a[n]+b[n];
    if(flag) cout<<ans<<"\n";
    else cout<<ans-1<<"\n";
}
void init() {
    flag=false; ans=0;
}
signed main() {
    freopen("inn.in","r",stdin);
    int T;scanf("%lld",&T);
    while(T--) {
        init(); solve();
    }
    return 0;
}

详细

Test #1:

score: 0
Time Limit Exceeded

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:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result: