QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#438746#8057. Best Carry Player 4stasio6#TL 898ms5872kbC++142.2kb2024-06-11 03:48:542024-06-11 03:48:54

Judging History

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

  • [2024-06-11 03:48:54]
  • 评测
  • 测评结果:TL
  • 用时:898ms
  • 内存:5872kb
  • [2024-06-11 03:48:54]
  • 提交

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]) continue;
                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]) continue;
                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';
    }
}

詳細信息

Test #1:

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

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: 0
Accepted
time: 66ms
memory: 5656kb

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

result:

ok 100000 numbers

Test #3:

score: 0
Accepted
time: 28ms
memory: 5644kb

input:

1000
500
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

0
1
1
2
2
2
0
0
0
3
1
1
2
0
1
0
1
1
3
0
0
4
3
1
4
4
0
0
2
1
3
3
0
0
1
0
1
1
0
0
2
1
2
0
3
1
3
1
3
4
2
1
1
2
3
0
0
1
2
0
0
1
1
1
1
2
1
2
2
0
2
2
1
1
3
0
0
1
2
0
1
3
0
0
1
1
0
0
1
0
3
1
2
0
0
5
1
1
1
3
1
4
1
0
0
0
0
0
1
3
1
2
1
0
0
0
0
0
1
1
0
4
0
1
1
3
0
1
0
0
2
3
0
1
2
1
1
1
0
3
0
0
3
2
1
1
0
1
0
1
...

result:

ok 1000 numbers

Test #4:

score: 0
Accepted
time: 662ms
memory: 5872kb

input:

100000
5
119777838 337555280 806504015 458289944 321614229
979242871 431783189 423329635 193632121 7339369
5
189264782 667669243 753322761 861814678 224007583
977519325 104432095 940220826 712094722 903574615
5
977791540 278658984 601762324 633391706 36807634
689562032 997406456 118939957 891425821 ...

output:

1377698543
2884329841
1699584169
2132012702
2531472710
2754014935
2585135038
2577893498
2034726862
2303377730
1476887044
2618960687
1626312268
1068946376
600795101
927483202
2151016849
2256729729
2291627593
1751199962
2412405837
1884010446
2553701265
2014856631
848686688
1069641213
2412585811
167144...

result:

ok 100000 numbers

Test #5:

score: 0
Accepted
time: 575ms
memory: 5668kb

input:

50000
10
18209490 798013131 762297136 184230300 323229686 771738936 850827138 201740028 818693101 945688434
101715068 966337103 309026840 698679951 666034197 810411289 841033024 740762082 484989962 19640395
10
608177485 700383507 317699894 982085408 908794603 92931066 880099629 965892642 576147264 9...

output:

5341540062
3811346608
3280168940
4222050470
4327730826
4389011469
5146997799
3799138189
4028437054
3650616128
4267213780
5220650313
3272450503
3560399774
5130261345
4384881302
4681302604
5415587476
2376088103
3344427945
3701410392
3434767065
4969556102
4474318648
4751503347
3701971157
5053000969
397...

result:

ok 50000 numbers

Test #6:

score: 0
Accepted
time: 526ms
memory: 5676kb

input:

5000
100
405163017 116989072 685766112 551211950 862199350 861827829 564364529 922314891 241721254 160976656 891732149 553649064 445152950 859742462 235262967 648909226 943054063 484936253 414150625 995061073 662853643 367723189 348457562 591856009 309322986 450413840 159926452 24214846 79239852 397...

output:

44348367445
47318596151
43893435579
49579921753
48669603728
45875221434
49002488594
53587378598
52208712766
49588253701
50196256163
49596309746
48141429048
49878478140
49036091100
46395088830
42672527744
41761915575
47439675311
47743457344
44672635972
50006245688
49397345810
46906644735
49589049416
...

result:

ok 5000 numbers

Test #7:

score: 0
Accepted
time: 647ms
memory: 5640kb

input:

500
1000
193550719 323493453 457420643 784509248 590688212 53858799 864840302 864699978 833248388 388148011 424847622 153776183 812936693 826657538 546327769 8986082 692715231 409800344 238099504 373879563 776749117 721714043 87525288 267321580 716697878 959194006 945266703 700945389 403532515 62661...

output:

465088900904
505514759606
489135202623
496905462876
484245812646
489774003871
497113250036
495356965473
487989876653
478735387405
492452909500
477359116614
476644416427
496024593454
511879486093
489977997571
487118685797
482393118166
500657058671
495034745130
463481958257
494092548341
498541253420
4...

result:

ok 500 numbers

Test #8:

score: 0
Accepted
time: 898ms
memory: 5844kb

input:

50
10000
553995858 246962428 824402293 323478911 680777105 103832678 585415164 992760839 343503903 178165091 12159583 994935001 342595423 59449818 679792998 816039830 731856694 560299370 549956669 133588429 444088799 47439002 33732378 667849963 779213360 312649757 413654325 204037978 407607851 37016...

output:

4934445638422
5004001488974
4977801387386
4989770542861
4943635086274
4943321860665
4991292690262
4973954855238
4988511939705
5018237958210
4977930376515
4933073917545
4971084263806
4946670696385
4936093052793
5021060989890
4950350493770
4983314449815
4983863160783
5008348159840
4971191273387
495994...

result:

ok 50 numbers

Test #9:

score: -100
Time Limit Exceeded

input:

5
100000
55467530 650020741 57699590 51967772 504211856 67871962 527800251 879255265 275707965 711280566 612286703 26282254 309510499 1918401 39869854 860668290 361753493 794313666 928775160 911047415 93046944 491539438 414230658 370192146 951557038 97990007 385352159 233363349 16821851 997867917 52...

output:

49811853885925
49898102768915
49899712412574
50041437439141
49960859308453

result: