QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#553939#6122. Impossible-to-finish RaceRafat_KabirAC ✓34ms4800kbC++203.2kb2024-09-08 23:22:212024-09-08 23:22:22

Judging History

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

  • [2024-09-08 23:22:22]
  • 评测
  • 测评结果:AC
  • 用时:34ms
  • 内存:4800kb
  • [2024-09-08 23:22:21]
  • 提交

answer

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <time.h>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>

using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>

using namespace __gnu_pbds;
using namespace std;
template <class T>
using Tree =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// to erase in multiset-> less_equal<T> and 
// s.erase(s.find_by_order(s.order_of_key(x)))
// lower_bound(x)=>(cannot use the stl lower_bound function)
// ll idx = s.order_of_key(x)
// if(idx == s.size()) -> no lower_bound
// else lb = *s.find_by_order(idx) // as 0-indexing
// idx-1 will give highest value which is strictly less than x
// for upper_bound->do the same with (x+1)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef tuple<ll, ll, ll> t64;
typedef vector<t64> vt64;
typedef vector<vt64> vvt64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef vector<vector<p32> > vvp32;
typedef vector<bool> vb;
ll mod =  1e9+7, MOD = 998244353;
double eps = 1e-12;
// #define forn(i,e) for(ll i = 0; i < e; i++)
#define FOR(s, e, i) for(int i = s; i <= e; i++)
// #define rforn(i,s) for(ll i = s; i >= 0; i--)
#define ROF(s ,e, i) for(int i = s; i >= e; i--)
#define coutAll(A) for(auto asdafas : A) cout <<  asdafas << " "; cout << "\n";
#define foutAll(A) for(auto asdafas : A) fout <<  asdafas << " "; cout << "\n";
#define cinAll(A) for(auto &asdafas : A) cin >>  asdafas;
#define finAll(A) for(auto &asdafas : A) fin >>  asdafas;
#define minpq priority_queue<ll, v64, greater<ll>>
#define maxpq priority_queue<ll> 
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
ll inf = LLONG_MAX;
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> pll;
typedef pair<ll, ll> pii;
//#define MAXN 1000000

void solve(int it)
{
    ll s, n;
    cin >> s >> n;
    vp64 A(s);
    FOR(0, s - 1, i){
        cin >> A[i].se >> A[i].fi;
    }
    sort(all(A));
    v64 dp(n+1, -1e15);
    ll ans = -1e15;
    FOR(0, s - 1, i){
        v64 nxt = dp;
        ROF(n, 2, j){
            nxt[j] = max(nxt[j], dp[j-1]+A[i].se);
        }
        nxt[1] = max(nxt[1], A[i].fi+A[i].se);
        dp = nxt;
        ans = max(ans, dp[n]-A[i].fi);
    }
    cout << ans;
}


int main()
{
    fast_cin();    
    ll t = 1;
    // cin >> t;
    for(int it=1; it<=t; it++)
    {
        //cout << "Case " << it << ": ";
        solve(it);
    }
    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3588kb

input:

4 2
40 150
100 185
60 160
80 170

output:

165

result:

ok 1 number(s): "165"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3548kb

input:

4 3
40 150
100 185
60 160
80 170

output:

215

result:

ok 1 number(s): "215"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

4 3
40 150
100 300
60 160
80 140

output:

160

result:

ok 1 number(s): "160"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

10 5
31 41
59 26
53 58
97 93
23 84
62 64
33 83
27 95
2 84
19 71

output:

237

result:

ok 1 number(s): "237"

Test #5:

score: 0
Accepted
time: 11ms
memory: 3796kb

input:

41152 111
182257016 930588061
48161946 238486760
972227016 5356065
86027096 260499041
669036106 225099150
237412554 751531756
242943966 295403431
389306712 171941587
805402434 808802744
223087510 185548988
484802407 630362813
909265069 146703978
669049492 795632652
880214973 687316602
917988759 1140...

output:

110260223222

result:

ok 1 number(s): "110260223222"

Test #6:

score: 0
Accepted
time: 15ms
memory: 3836kb

input:

48742 151
4172512 232468953
174593775 315428416
755598560 502830675
153875037 669103745
655189533 251356834
742835852 504736254
57702809 81033220
522268929 496624663
916420651 11925854
636090457 18793771
59670306 212773533
266630484 168697702
249848762 90639194
167795884 521046550
275829432 75048104...

output:

150042793971

result:

ok 1 number(s): "150042793971"

Test #7:

score: 0
Accepted
time: 4ms
memory: 3488kb

input:

10832 185
384369718 813482411
710792603 515157830
552246538 364938172
118387323 558137174
960264583 110630
883245504 400769573
912502469 245524014
160032703 685924756
784192091 291966573
855188194 828271633
957837360 194604250
571403510 177773109
746568096 669989013
294755059 430843816
570306962 862...

output:

182319609909

result:

ok 1 number(s): "182319609909"

Test #8:

score: 0
Accepted
time: 6ms
memory: 3600kb

input:

18148 181
317375491 959619539
283021787 485619692
474951974 984085468
295380316 824207087
152625734 650222645
190338285 195156360
311736957 338390028
289661673 796666562
605193885 709391445
466977224 332169628
524062708 562163672
676469373 606455442
487555874 770717667
492775549 65447403
154084339 9...

output:

179257349651

result:

ok 1 number(s): "179257349651"

Test #9:

score: 0
Accepted
time: 6ms
memory: 3788kb

input:

20517 119
81770998 83447880
733395187 340904766
51692224 631824159
247762158 720798400
753102635 46716151
400316097 440030572
411675274 726057252
881612034 894407953
681714230 187307136
951565981 858102613
570176402 341903964
829157317 310766291
226552528 637766332
733441545 358801637
414258293 6001...

output:

117841021264

result:

ok 1 number(s): "117841021264"

Test #10:

score: 0
Accepted
time: 30ms
memory: 4580kb

input:

93044 182
813695274 153887021
542126825 663951320
364280184 904341637
291766688 257121248
75639269 180912022
825451471 22204002
473902802 454694292
611075180 805611054
844482533 903659112
773663466 532233047
138575839 944906705
668819264 137394165
225354534 384383944
510444964 359732925
763300639 60...

output:

181211463696

result:

ok 1 number(s): "181211463696"

Test #11:

score: 0
Accepted
time: 6ms
memory: 3568kb

input:

25784 53
798294768 320766717
429746760 294501271
644419286 801462427
724066936 339399074
657789061 573676913
970005050 661268530
426332867 254169739
153700078 827586236
289134392 246530412
788279593 302899440
39720539 183658008
615865661 431061664
941027421 67440607
851264422 537004856
427260246 891...

output:

52567930451

result:

ok 1 number(s): "52567930451"

Test #12:

score: 0
Accepted
time: 23ms
memory: 4364kb

input:

85083 117
933728908 166830648
315791188 439632784
325837679 115125521
270329800 873456540
640213196 243297796
914696498 111637314
824743768 733251609
879223039 702511677
601533585 506847766
388042178 540773701
584502053 164333442
235718823 825003326
160442761 580351903
112999161 343919921
120241611 ...

output:

116486732641

result:

ok 1 number(s): "116486732641"

Test #13:

score: 0
Accepted
time: 6ms
memory: 3496kb

input:

21476 97
63429284 292081968
724418165 393470825
255101780 520874265
537856330 530859115
387052107 227378228
955779689 938747569
362382510 470288870
758017146 980866850
95193697 896397143
347630065 188685241
993612425 674170903
335151627 886335139
549751105 54769792
966979302 796574615
770088067 1448...

output:

96145475777

result:

ok 1 number(s): "96145475777"

Test #14:

score: 0
Accepted
time: 22ms
memory: 4680kb

input:

96285 26
455028034 39251727
824295989 385236424
63399198 102638857
387334356 581156661
454974662 709028736
900399312 684211451
149763651 644418604
32511388 718985488
660630420 211641780
486912715 466693387
686434645 485294856
493518359 822845210
221767398 816352162
507764176 223798302
47074048 79690...

output:

25916772196

result:

ok 1 number(s): "25916772196"

Test #15:

score: 0
Accepted
time: 33ms
memory: 4584kb

input:

100000 200
236287670 804039413
140506636 670751691
331381204 895007340
852265703 736737899
804066444 277236557
237844614 812494506
55084996 90201715
876812302 513418441
584034127 726487185
844521069 244127643
361613896 694711811
154016310 831976968
244847489 447480031
424060659 682670356
139039667 9...

output:

199215953571

result:

ok 1 number(s): "199215953571"

Test #16:

score: 0
Accepted
time: 30ms
memory: 4572kb

input:

100000 200
438541603 699411539
45417102 957932414
304996950 512547237
584684086 961533781
85093785 624474586
91726999 104157166
291779221 957187862
786912201 353204590
400062744 185413463
694278118 784865714
851265992 756883083
536887012 820028712
190249867 137695614
722578103 999507904
301485310 35...

output:

199134024482

result:

ok 1 number(s): "199134024482"

Test #17:

score: 0
Accepted
time: 30ms
memory: 4800kb

input:

100000 200
7869483 240665921
517875314 503237636
3205902 925930729
143045670 194790167
330039680 721900494
63022288 593543362
941594188 927093988
920949625 753039988
853635654 294002372
65745113 167910923
237381758 796352381
967179707 239125243
988173949 818397040
425777074 96442630
51201807 4944016...

output:

199126570851

result:

ok 1 number(s): "199126570851"

Test #18:

score: 0
Accepted
time: 26ms
memory: 4604kb

input:

100000 200
902153908 142027280
491509782 851124712
6599211 436319431
913466861 322115820
57493938 710409781
74833645 399824586
562099895 427843643
14156121 864906695
830614130 723066316
669677424 572708011
937925307 6248069
722530198 429178594
616408073 911018995
797450175 679990995
712580391 689235...

output:

199142450154

result:

ok 1 number(s): "199142450154"

Test #19:

score: 0
Accepted
time: 34ms
memory: 4608kb

input:

100000 200
939641504 778976225
778616835 2958301
368789217 929481585
427443141 605128056
331854886 134924969
908388080 427473861
203966828 516359881
942628120 182970193
321917044 900091744
616518555 532100761
665778808 981854704
866908765 109120055
489523878 899555399
974545907 788211427
610866724 6...

output:

199177375050

result:

ok 1 number(s): "199177375050"

Test #20:

score: 0
Accepted
time: 34ms
memory: 4616kb

input:

100000 200
583328109 554198621
562525804 662027941
725614636 75659819
948042884 477667597
596983489 886129587
792076150 150285026
462832527 880401700
334081616 953611058
268591216 657464705
6154469 576624039
718168742 157125273
475875972 528059530
933799823 886898046
164353212 854376951
263532606 33...

output:

199175464473

result:

ok 1 number(s): "199175464473"

Test #21:

score: 0
Accepted
time: 33ms
memory: 4680kb

input:

100000 200
808513977 693609959
113456635 805685032
749222875 784057935
512349672 480807957
190888767 553755075
549381310 417267049
688640871 688573004
248221644 502151017
158194613 184746652
738824951 167915607
55980081 95216084
838640235 199108433
116057004 899224809
503327466 718196997
226537968 9...

output:

199136249264

result:

ok 1 number(s): "199136249264"

Test #22:

score: 0
Accepted
time: 34ms
memory: 4604kb

input:

100000 200
449001049 695315428
978310626 438967643
795100890 183356799
190894562 276681907
649706302 73327984
903229801 421547301
746685377 741806243
541298524 356085904
898002540 507512328
24664064 798539118
688386794 854172435
824926706 104337396
892307134 162706216
788773015 63384255
487326808 86...

output:

199169029575

result:

ok 1 number(s): "199169029575"

Test #23:

score: 0
Accepted
time: 29ms
memory: 4672kb

input:

100000 200
444178781 356527699
529067437 801914346
665271123 538072264
956196567 812162423
615549469 549136686
939822396 465446774
265968471 255876890
372664828 265062579
524359005 914735255
472087053 67462564
703870929 115331092
804397128 361386687
762455723 702740230
41107646 323309719
146634035 7...

output:

199146249202

result:

ok 1 number(s): "199146249202"

Test #24:

score: 0
Accepted
time: 30ms
memory: 4788kb

input:

100000 200
655846365 313661203
390366508 158862627
527184479 984287389
309597946 579207531
794937319 321271765
706090082 948555033
618523013 107471453
621983726 940529266
562426216 415859210
321935327 513511252
748344017 347120895
217118746 322199855
81080463 967391225
258456215 820218495
787827813 ...

output:

199199818297

result:

ok 1 number(s): "199199818297"

Test #25:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

2 2
1 1000000000
1000000000 1

output:

2

result:

ok 1 number(s): "2"

Test #26:

score: 0
Accepted
time: 0ms
memory: 3464kb

input:

2 2
1 1000000000
1 1

output:

-999999997

result:

ok 1 number(s): "-999999997"

Test #27:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

200 200
832389878 271044862
71070899 504340371
912900693 325041542
504067161 271327382
833455367 394595095
506978832 240062738
734214661 504285209
717534322 482651310
510898733 872555736
175301434 768829912
391606846 13107072
393006456 974016395
448546064 822560580
676221324 805445063
407319269 2530...

output:

107479788170

result:

ok 1 number(s): "107479788170"

Test #28:

score: 0
Accepted
time: 0ms
memory: 3536kb

input:

200 200
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
100000...

output:

200000000000

result:

ok 1 number(s): "200000000000"

Test #29:

score: 0
Accepted
time: 34ms
memory: 4624kb

input:

100000 200
1000000000 78517909
1000000000 500311177
1000000000 293785522
1000000000 954237907
1000000000 882968874
1000000000 134408655
1000000000 552621244
1000000000 19461143
1000000000 951319484
1000000000 873867203
1000000000 933129813
1000000000 824346657
1000000000 305877734
1000000000 9029348...

output:

199998531281

result:

ok 1 number(s): "199998531281"

Test #30:

score: 0
Accepted
time: 30ms
memory: 4608kb

input:

100000 200
113401148 1000000000
910622498 1000000000
437673863 1000000000
94487241 1000000000
254064871 1000000000
457253831 1000000000
567763265 1000000000
816041200 1000000000
340366554 1000000000
725083245 1000000000
437112787 1000000000
478317431 1000000000
122307300 1000000000
558373892 1000000...

output:

199818861002

result:

ok 1 number(s): "199818861002"