QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#438744#8057. Best Carry Player 4stasio6#WA 77ms3612kbC++142.1kb2024-06-11 03:40:512024-06-11 03:40:51

Judging History

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

  • [2024-06-11 03:40:51]
  • 评测
  • 测评结果:WA
  • 用时:77ms
  • 内存:3612kb
  • [2024-06-11 03:40:51]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define rep(i,a,b) for(int i = a; i < (b); i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define PB push_back
#define FS first
#define SD second
template<class A, class B> void cmx(A& x, B y) {x=max<A>(x, y);}
template<class A, class B> void cmn(A& x, B y) {x=min<A>(x, y);}
typedef pair<int, int> pii;
typedef vector<int> vi;
int a[500005],b[500005];
signed main() {
    cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit);
    int T;
    cin>>T;
    while(T--){
        int n;
        cin>>n;
        for(int i=1;i<=n;i++) cin>>a[i];
        for(int i=1;i<=n;i++) cin>>b[i];
        int suma=0,sumb=0;
        for(int i=1;i<=n;i++) suma+=a[i];
        for(int i=1;i<=n;i++) sumb+=b[i];
        if(suma<sumb) a[1]+=sumb-suma;
        else b[1]+=suma-sumb;
        int tot=max(suma,sumb);
        int l=0,r=tot;
        while(l<r){
            int mid=(l+r+1)>>1;
            vector <pair<int,int>> va,vb;
            for(int i=n,ra=mid;i&&ra;i--){
                if(a[i]>=ra){
                    va.push_back({i,ra});
                    break;
                }
                else va.push_back({i,a[i]}),ra-=a[i];
            }
            for(int i=n,rb=mid;i&&rb;i--){
                if(b[i]>=rb){
                    vb.push_back({i,rb});
                    break;
                }
                else vb.push_back({i,b[i]}),rb-=b[i];
            }
            sort(va.begin(),va.end());
            sort(vb.begin(),vb.end(),greater<pair<int,int>>());
            int pa=0,pb=0,mx=0,fl=1;
            while(pa<va.size()&&pb<vb.size()){
                int ra=va[pa].second,rb=vb[pb].second,mn=min(ra,rb);
                va[pa].second-=mn,vb[pb].second-=mn;
                if(va[pa].first+vb[pb].first-2<n-1) fl=0;
                mx=max(mx,va[pa].first+vb[pb].first);
                if(va[pa].second==0) pa++;
                if(vb[pb].second==0) pb++;
            }
            if(fl&&mx-2>=n){
                l=mid;
            }
            else r=mid-1;
        }
        cout<<l<<'\n';
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 77ms
memory: 3612kb

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

result:

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