QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#709060#8057. Best Carry Player 4frankly6WA 14ms7712kbC++171.3kb2024-11-04 11:06:432024-11-04 11:06:44

Judging History

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

  • [2024-11-04 11:06:44]
  • 评测
  • 测评结果:WA
  • 用时:14ms
  • 内存:7712kb
  • [2024-11-04 11:06:43]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#define int long long
using namespace std;
const int MX=500050;
const int inf=1e15;

int T, N;
int ar[MX], br[MX], suf[MX];
int read()
{
    int r=0, f=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') {r=r*10+ch-'0'; ch=getchar();}
    return r*f;
}
signed main()
{
    // freopen("testdata.in","r",stdin);
    T=read();
    while(T--)
    {
        N=read();
        int sa=0, sb=0;
        for(int i=0;i<N;i++) ar[i]=read(), sa+=ar[i];
        for(int i=0;i<N;i++) br[i]=read(), sb+=br[i];
        sa-=ar[N-1]; sb-=br[N-1];
        int sum=0, suf=0, tag=1;
        for(int i=1;i<N-1;i++)
        {
            suf+=br[N-1-i];
            int num=min(ar[i],suf);
            suf-=num;
            sum+=num; 
            if(suf!=0) tag=0;
        }
        suf=0;
        for(int i=1;i<N-1;i++)
        {
            suf+=ar[N-1-i];
            int num=min(br[i],suf);
            suf-=num;
            sum+=num; 
            if(suf!=0) tag=0;
        }
        sum/=2;
        if(sa-sum>=br[N-1]||sb-sum>=ar[N-1]) sum+=ar[N-1]+br[N-1];
        else
        {
            sum+=max(sa-sum+br[N-1],sb-sum+ar[N-1]);
            tag=0;
        }
        cout << sum-tag << '\n';
    }
    return (0-0);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7636kb

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: 14ms
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
1
3
1
1
0
0
0
1
1
4
1
4
1
0
2
4
3
1
5
1
0
2
1
1
1
1
0
1
3
5
3
2
2
2
0
1
2
3
2
0
5
1
2
1
1
0
1
0
4
2
2
2
2
0
3
3
0
2
0
1
0
1
2
1
2
1
3
4
0
2
5
0
2
1
1
1
0
3
2
3
0
2
1
4
3
3
1
2
2
2
1
3
1
1
0
1
0
1
0
3
2
2
0
2
1
1
1
2
-1
1
2
4
1
3
3
2
2
2
0
2
0
1
2
3
1
3
1
0
3
2
3
0
1
2
1
1
1...

result:

wrong answer 14th numbers differ - expected: '0', found: '1'