QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#95676 | #71. Cake 3 | tricyzhkx | 0 | 5ms | 7820kb | C++14 | 1.6kb | 2023-04-11 12:57:42 | 2023-04-11 12:57:45 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e18;
int n,m,len,vv[200010],rt[200010],lc[4000010],rc[4000010],cnt[4000010],tot=1;
ll sum[4000010],ans=-INF;
struct node
{
int V,C;
bool operator<(const node &a)const{return C<a.C;}
}a[200010];
void update(int &rt,int l,int r,int x)
{
cnt[++tot]=cnt[rt];sum[tot]=cnt[rt];lc[tot]=lc[rt];rc[tot]=rc[rt];rt=tot;
if(l==r) return cnt[rt]++,sum[rt]+=vv[l],void();
int mid=(l+r)/2;
if(x<=mid) update(lc[rt],l,mid,x);
else update(rc[rt],mid+1,r,x);
cnt[rt]=cnt[lc[rt]]+cnt[rc[rt]];
sum[rt]=sum[lc[rt]]+sum[rc[rt]];
}
ll query(int rt1,int rt2,int l,int r,int x)
{
if(l==r) return (ll)x*vv[l];
int mid=(l+r)/2;
if(cnt[rc[rt2]]-cnt[rc[rt1]]>=x) return query(rc[rt1],rc[rt2],mid+1,r,x);
else return query(lc[rt1],lc[rt2],l,mid,x-(cnt[rc[rt2]]-cnt[rc[rt1]]))+sum[rc[rt2]]-sum[rc[rt1]];
}
ll W(int i,int j)
{
if(i>j || cnt[rt[j]]-cnt[rt[i-1]]<m) return -INF;
return query(rt[i-1],rt[j],1,len,m)+2*a[i].C-2*a[j].C;
}
void solve(int l,int r,int x,int y)
{
if(l>r) return;
int mid=(l+r)/2,p=0;
ll maxn=-INF,t;
for(int i=x;i<=y && i<=mid-m+1;i++)
if((t=W(i,mid))>maxn) maxn=t,p=i;
ans=max(ans,maxn);
solve(l,mid-1,x,p);solve(mid+1,r,p,y);
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++) scanf("%d%d",&a[i].V,&a[i].C),vv[++len]=a[i].V;
sort(a+1,a+n+1);
sort(vv+1,vv+len+1);
len=unique(vv+1,vv+len+1)-vv-1;
auto get=[](int v){return lower_bound(vv+1,vv+len+1,v)-vv;};
for(int i=1;i<=n;i++) a[i].V=get(a[i].V);
for(int i=1;i<=n;i++) update(rt[i]=rt[i-1],1,len,a[i].V);
solve(m,n,1,n-m+1);
cout<<ans<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 5
Accepted
time: 2ms
memory: 3696kb
input:
100 32 671208774 266481733 115497791 342597239 326245300 76223942 528973483 754205900 437996819 995535247 100582194 42402057 771100621 351934207 89058009 81951602 768935397 186435060 842907845 376386254 187943947 59424920 997369107 493642356 455078419 68850493 542835555 938351581 970171972 611243076...
output:
25580474644
result:
ok single line: '25580474644'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3548kb
input:
96 26 654901552 458347153 165510759 938829925 195217130 507375330 505924632 413472221 654752848 711653336 843934470 721570198 773665886 401710037 234904469 980379861 955790468 908963841 767941919 649831102 551860594 482287589 445315312 465411688 121261567 38031091 85608696 831434175 898543690 533481...
output:
20912597347
result:
ok single line: '20912597347'
Test #3:
score: 0
Accepted
time: 2ms
memory: 5580kb
input:
97 50 601727246 586947184 629061466 495053188 908476392 789027930 127214423 866336725 518731382 132785533 113489768 827723755 985313205 850125600 651615014 585565934 7844301 974793551 821451342 503266415 191392244 172018292 811053096 980886405 414007158 116164410 749815864 858185057 809840877 654635...
output:
35572528711
result:
ok single line: '35572528711'
Test #4:
score: 0
Accepted
time: 3ms
memory: 5528kb
input:
95 53 149550762 262774006 70645562 988470529 951317142 587455395 640797744 881023050 152099375 109591790 42073955 240106850 787394186 32306392 690229700 154829125 612427906 799230609 529294971 846139787 399369072 840851479 258683206 624167919 933584741 989196725 928112368 809131208 742906726 7228213...
output:
38104623964
result:
ok single line: '38104623964'
Test #5:
score: 0
Accepted
time: 5ms
memory: 7612kb
input:
95 67 219655106 209971230 684228500 55963835 376681839 957451928 44063570 464399636 244459351 255445846 926539875 699539831 624720901 149661354 268068448 124041530 391618918 196971593 259894666 522352998 72651673 750483217 418558834 288939175 987660441 756241680 290013706 540390088 672554190 1595528...
output:
42726885227
result:
ok single line: '42726885227'
Test #6:
score: 0
Accepted
time: 2ms
memory: 3548kb
input:
98 83 144189007 599184430 955720138 430137031 46813950 337012077 284624496 923370172 585878255 277696686 458874123 25220195 65996741 918738892 536999214 420249860 124871436 785740035 524616035 321557657 377122912 363899088 800060966 799482628 704695498 739563311 385588901 543586072 594428502 6483895...
output:
47720376527
result:
ok single line: '47720376527'
Test #7:
score: 0
Accepted
time: 2ms
memory: 3600kb
input:
96 38 37921502 265183642 30462271 269145614 51895518 29824956 44764507 681512686 47724467 815499441 6427327 591731270 46504734 436644698 2223048 132007665 40380520 511674250 43917077 653531209 17511337 975498424 1931641 115779401 16884852 128795730 14731353 429591965 5850509 790146440 15255306 77070...
output:
399264493
result:
ok single line: '399264493'
Test #8:
score: 0
Accepted
time: 3ms
memory: 7820kb
input:
96 25 57401007 493943697 29527957 714663679 29545307 647011203 41025179 566266756 58441740 117870293 27412280 422916085 33052858 310233747 9411800 715114198 15661682 773129023 49930623 903197292 4733526 653650922 36089642 500031319 1389486 444206729 19886177 397683562 2903725 764846753 84795 2145521...
output:
719815801
result:
ok single line: '719815801'
Test #9:
score: 0
Accepted
time: 2ms
memory: 5576kb
input:
99 21 59657805 652963568 80731103 249217474 67765017 136600735 30669693 235796790 38336275 333697289 9339946 754166690 69051138 182211402 93041255 259466527 71372493 445676674 67165121 840321934 33766102 430254036 18248715 148433501 38354832 282537749 64069877 131281615 39361263 592884334 18160924 9...
output:
888797889
result:
ok single line: '888797889'
Test #10:
score: 0
Accepted
time: 3ms
memory: 7720kb
input:
93 28 19252348 834865987 35189109 821648351 47848765 934801179 33900007 907328375 45481720 478428955 4292036 880931858 36991135 956842947 49181931 583677473 36889879 714660270 20737289 866325358 65602596 635999283 70856516 855441876 54559432 319956854 47217522 132918942 55127890 62037126 53412038 84...
output:
597761343
result:
ok single line: '597761343'
Test #11:
score: 0
Accepted
time: 3ms
memory: 7720kb
input:
92 18 17034692 311412535 75067760 700238328 85371763 32662981 90417142 594066624 34625146 420051930 46026136 298353430 71930456 679253686 94901612 553915166 10855990 339449028 10327620 444733804 51133091 802733614 95838938 276886845 22327317 53898064 29910663 881733161 74599342 280465633 8898777 221...
output:
963264484
result:
ok single line: '963264484'
Test #12:
score: 0
Accepted
time: 2ms
memory: 5572kb
input:
96 46 3613091 48226953 17333738 315657491 33499557 905024 21585984 973060800 42148202 275277748 25892629 489251559 31604703 888333915 13970358 799610574 33246317 54304803 7114447 61375639 5669373 697687696 1575366 350398758 16667098 747366614 7839377 799378407 18868553 430864652 41883674 476142622 1...
output:
217389025
result:
ok single line: '217389025'
Test #13:
score: 0
Accepted
time: 2ms
memory: 5632kb
input:
100 45 43924230 212784715 43573365 390630448 36356410 302155896 8834549 369231487 23914662 209393152 8961292 339488011 11770598 98213199 41391432 553642288 33929359 654885451 15834215 243511760 32889505 785116193 40157572 806063390 41729010 657312356 24502770 98898149 33168308 379445567 25788178 737...
output:
284124804
result:
ok single line: '284124804'
Test #14:
score: 0
Accepted
time: 3ms
memory: 7768kb
input:
94 44 18278964 59117371 1121774 674793869 44776633 866596597 3672456 43798662 18327992 258671822 26820827 436747027 10741961 269663794 4454544 235521073 2959148 111403543 17994812 431349737 44808537 631076314 1072950 366206930 37219572 987766907 33824148 367550034 18542970 307178475 1386716 33940913...
output:
308368925
result:
ok single line: '308368925'
Test #15:
score: 0
Accepted
time: 2ms
memory: 3648kb
input:
96 41 36332583 8569405 20284590 704164692 26169208 400229170 32850340 485895095 44691003 149746532 5684161 537586304 3545889 108210000 26693523 480026681 38944140 61394964 34125662 576589094 10604727 179814783 12192083 364751818 37385170 791694556 20134304 90024835 19149660 168146967 11032310 183184...
output:
344295172
result:
ok single line: '344295172'
Test #16:
score: 0
Accepted
time: 0ms
memory: 5564kb
input:
90 38 8869730 76738045 32276119 757676479 5091410 369590827 35491028 689930909 20025995 127998287 49111097 975894312 16776797 690236150 14603906 430533164 6638017 768678637 583367 277491929 43583227 197845857 19225748 735413656 39437324 641580882 43275662 785441666 50322818 734853329 35990613 997504...
output:
418654054
result:
ok single line: '418654054'
Test #17:
score: 0
Accepted
time: 0ms
memory: 5572kb
input:
97 63 17888788 608002691 16142900 885752870 1364666 365868015 4878248 624150124 18576418 704242346 17020617 375882628 21749764 987510302 23736619 444353886 19722113 954714013 9275566 579405076 31641382 557924314 28779133 996785377 24059182 892591765 26116965 249236656 15958669 36018002 12783153 4066...
output:
-324021706
result:
ok single line: '-324021706'
Test #18:
score: 0
Accepted
time: 2ms
memory: 3556kb
input:
100 71 14246084 541505816 9994802 994431615 1482902 185840951 26468202 241171629 17716658 549877382 25340166 772809756 18151090 18915661 10164740 748716089 12552723 56489026 6069755 574352885 23096929 778200711 24642227 384490457 4716312 797733167 23906409 557004993 197262 5593534 27176008 844798422...
output:
-276543166
result:
ok single line: '-276543166'
Test #19:
score: 0
Accepted
time: 2ms
memory: 5576kb
input:
97 65 4386932 310542657 23651846 24902512 17872222 432076283 12688150 320458048 13294064 783055998 24489246 667018801 26933633 303216574 20987206 894751368 6946734 18906053 4725483 816674619 11278516 963601520 1714355 137847174 16817734 79470468 7807193 972225264 15832623 861238054 11363869 91575309...
output:
-174786613
result:
ok single line: '-174786613'
Test #20:
score: 0
Accepted
time: 2ms
memory: 3528kb
input:
100 76 19363945 999230932 6565531 340746079 17098814 481571520 15063962 562888079 16400153 379641015 22687207 473072780 13205572 315563624 4971425 266006726 25882141 800667318 16425184 781371894 10021910 67574149 19963913 96397646 26310382 585714937 7145348 578506544 4794238 790460340 7285540 645057...
output:
-310560206
result:
ok single line: '-310560206'
Test #21:
score: 0
Accepted
time: 2ms
memory: 5564kb
input:
95 66 12740392 44322988 23072578 479866996 28690034 991246669 23341774 816240165 5356957 510095701 6993836 351625358 16797983 601213241 16864568 335398045 13997193 909507175 27087288 982552754 26886506 169380803 3047418 849902451 1896289 226928494 1306707 244984996 13019901 587922276 11247618 716796...
output:
-28999886
result:
ok single line: '-28999886'
Test #22:
score: -5
Wrong Answer
time: 2ms
memory: 5580kb
input:
94 22 17729830 195028137 17729832 195028150 17729830 195028178 17729832 195028140 17729832 195028118 17729836 195028176 17729835 195028180 17729829 195028198 17729829 195028141 17729835 195028132 17729834 195028115 17729829 195028197 17729829 195028160 17729829 195028137 17729834 195028161 17729836 ...
output:
248217583
result:
wrong answer 1st lines differ - expected: '390056298', found: '248217583'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%