QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#46521 | #4202. Even Electricity | MoQz | AC ✓ | 24ms | 5380kb | C++ | 946b | 2022-08-30 10:06:41 | 2022-08-30 10:06:43 |
Judging History
answer
#include<iostream>
#include<cstdio>
using namespace std;
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fod(i,a,b) for(int i=a;i>=b;--i)
#define LL long long
LL read(){
LL u=0;
char c=getchar();
while(c>'9'||c<'0')c=getchar();
while(c>='0'&&c<='9')u=u*10+c-48,c=getchar();
return u;
}
int n;
LL r2,s[200011],w[200011];
int solve_l(LL l){
LL R=0;
fo(i,1,n){
R=min(R+w[i],min(r2,R+w[i]-l+s[i]));
if(R<0)return 0;
}
return 1;
}
int solve_r(LL r){
LL L=0;
fo(i,1,n){
L=L+w[i]-r+s[i];
if(L<0)L=0;
if(L>r2||(i==n&&L>0))return 0;
}
return 1;
}
int main(){
n=read();
r2=read();
fo(i,1,n){
s[i]=read();
w[i]=read();
}
LL ans=0;
LL l=0,r=2000000001,mid;
while(l<r){
mid=(l+r+1)/2;
if(solve_l(mid))l=mid;
else r=mid-1;
}
ans-=l;
l=0,r=2000000001,mid;
while(l<r){
mid=(l+r)/2;
if(solve_r(mid))r=mid;
else l=mid+1;
}
printf("%lld",ans+r);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3700kb
input:
3 1 4 2 2 0 5 1
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3676kb
input:
1 10 10 9
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3664kb
input:
2 10 6 10 9 6
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 2ms
memory: 3664kb
input:
10 10 5 6 8 0 1 8 2 2 7 5 5 3 10 6 3 0 9 2 0 9
output:
2
result:
ok single line: '2'
Test #5:
score: 0
Accepted
time: 2ms
memory: 3816kb
input:
10 10 6 1 9 1 8 10 2 5 8 10 6 10 10 9 4 8 0 1 0 6
output:
8
result:
ok single line: '8'
Test #6:
score: 0
Accepted
time: 2ms
memory: 3684kb
input:
10 10 4 9 4 3 2 2 10 7 6 9 3 5 5 8 7 4 0 4 8 2
output:
4
result:
ok single line: '4'
Test #7:
score: 0
Accepted
time: 2ms
memory: 3748kb
input:
10 10 6 7 5 0 5 9 9 6 2 2 0 3 2 10 4 8 1 6 2 9
output:
3
result:
ok single line: '3'
Test #8:
score: 0
Accepted
time: 22ms
memory: 5240kb
input:
100000 1000000000 413794426 487008076 857157934 416640558 335458362 938175747 331906268 815014691 884031347 954760972 747185588 109876528 795877270 347023646 687257733 17478773 649166691 883831823 683020200 450159267 250807459 945914456 375003437 674695585 585101823 862146285 765383066 602155570 285...
output:
1105061946
result:
ok single line: '1105061946'
Test #9:
score: 0
Accepted
time: 14ms
memory: 5288kb
input:
100000 1000000000 242077119 729724206 279044101 368837879 376881006 400928995 600291353 3398737 105837927 606968424 653114466 280439694 433127753 705813398 797330526 591799335 606747464 851192297 380825730 999336566 777818898 881558226 809144711 326167836 160650518 862351925 375940812 290070875 9581...
output:
1108081577
result:
ok single line: '1108081577'
Test #10:
score: 0
Accepted
time: 24ms
memory: 5332kb
input:
100000 1000000000 526097939 341763432 847150260 539385269 151198061 965181383 438329724 395601548 471761451 786498213 589692967 79420741 142047807 559437448 318348321 347781041 38687331 751499909 190623797 71750463 450528748 259219077 159485005 605128044 398566472 960935290 179478648 715733784 74058...
output:
1213605526
result:
ok single line: '1213605526'
Test #11:
score: 0
Accepted
time: 20ms
memory: 5308kb
input:
100000 1000000000 13201362 688008764 471723115 550879412 502385021 492967970 993776412 215495923 418646 441134117 899775024 717798730 796833224 937450002 578442539 977818344 744756004 540294838 446872174 592857446 341630081 64488239 352740110 758135828 262962096 403487879 207124761 260936746 1257939...
output:
1127515141
result:
ok single line: '1127515141'
Test #12:
score: 0
Accepted
time: 10ms
memory: 5260kb
input:
100000 10 9 8 3 10 10 4 1 6 2 3 4 4 3 6 10 10 3 8 6 2 4 9 4 8 7 0 6 6 0 9 8 8 5 6 10 2 2 3 10 8 5 8 8 7 9 6 6 7 7 2 6 6 10 9 2 3 8 10 1 0 5 5 7 8 0 10 4 5 0 1 6 9 6 3 3 4 6 1 4 10 3 6 8 4 2 8 0 7 4 0 4 1 0 0 8 10 9 2 7 9 2 1 7 0 8 5 5 3 0 4 4 1 6 0 6 3 9 1 9 10 1 6 2 6 10 10 8 4 0 8 10 10 5 8 2 0 0 ...
output:
14
result:
ok single line: '14'
Test #13:
score: 0
Accepted
time: 3ms
memory: 5340kb
input:
100000 1000000000 0 12 0 8 0 6 0 9 0 12 0 9 0 17 0 8 0 7 0 7 0 11 0 8 0 8 0 14 0 6 0 6 0 6 0 13 0 5 0 7 0 10 0 8 0 11 0 6 0 5 0 9 0 11 0 13 0 8 0 6 0 8 0 9 0 9 0 4 0 9 0 5 0 11 0 14 0 10 0 8 0 12 0 7 0 7 0 3 0 9 0 9 0 8 0 3 0 7 0 9 0 11 0 7 0 12 0 11 0 10 0 4 0 8 0 8 0 12 0 3 0 5 0 6 0 4 0 9 0 3 0 9...
output:
0
result:
ok single line: '0'
Test #14:
score: 0
Accepted
time: 10ms
memory: 5168kb
input:
100000 1000000000 0 12 0 8 0 6 0 9 0 12 0 9 0 17 0 8 0 7 0 7 0 11 0 8 0 8 0 14 0 6 0 6 0 6 0 13 0 5 0 7 0 10 0 8 0 11 0 6 0 5 0 9 0 11 0 13 0 8 0 6 0 8 0 9 0 9 0 4 0 9 0 5 0 11 0 14 0 10 0 8 0 12 0 7 0 7 0 3 0 9 0 9 0 8 0 3 0 7 0 9 0 11 0 7 0 12 0 11 0 10 0 4 0 8 0 8 0 12 0 3 0 5 0 6 0 4 0 9 0 3 0 9...
output:
1
result:
ok single line: '1'
Test #15:
score: 0
Accepted
time: 22ms
memory: 5232kb
input:
100000 1000000000 1000000000 10012 1000000000 10008 1000000000 10006 1000000000 10009 1000000000 10012 1000000000 10009 1000000000 10017 1000000000 10008 1000000000 10007 1000000000 10007 1000000000 10011 1000000000 10008 1000000000 10008 1000000000 10014 1000000000 10006 1000000000 10006 1000000000...
output:
0
result:
ok single line: '0'
Test #16:
score: 0
Accepted
time: 13ms
memory: 5380kb
input:
100000 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 1000000...
output:
0
result:
ok single line: '0'
Test #17:
score: 0
Accepted
time: 18ms
memory: 5252kb
input:
100000 1 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 10000...
output:
15
result:
ok single line: '15'
Test #18:
score: 0
Accepted
time: 10ms
memory: 5380kb
input:
100000 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1...
output:
1
result:
ok single line: '1'
Test #19:
score: 0
Accepted
time: 23ms
memory: 5332kb
input:
100000 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 1000000...
output:
12349
result:
ok single line: '12349'
Test #20:
score: 0
Accepted
time: 19ms
memory: 5328kb
input:
100000 999999999 663307072 1000000000 993786078 1000000000 572589545 1000000000 762227827 1000000000 392826687 1000000000 613084012 1000000000 628984380 1000000000 785866094 1000000000 177905367 1000000000 832364258 1000000000 885164571 1000000000 357329819 1000000000 411999901 1000000000 681690681 ...
output:
565400472
result:
ok single line: '565400472'
Test #21:
score: 0
Accepted
time: 15ms
memory: 5168kb
input:
100000 999999999 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 10000000...
output:
0
result:
ok single line: '0'
Test #22:
score: 0
Accepted
time: 6ms
memory: 5172kb
input:
100000 1000000000 734943030 479634570 780191377 139307617 906138352 112472025 51036612 938461968 472843829 486515748 98634840 465110469 729848614 348492342 660721903 892923455 906001148 903787964 398915355 438127471 410215291 334632055 82675972 332519938 693595168 799822567 4263928 353474876 5238419...
output:
1546183137
result:
ok single line: '1546183137'
Test #23:
score: 0
Accepted
time: 5ms
memory: 5252kb
input:
100000 100000 92754 7162 23570 1951 68132 88311 34040 3641 18165 69054 39959 52549 79013 12 75840 66547 16056 56552 7436 43586 61866 67509 37014 28215 25544 37135 38257 34487 1847 76800 85428 6569 32139 79601 7453 76504 46188 39096 43941 64367 56955 32656 61928 75581 66406 46108 37745 61273 51350 27...
output:
149569
result:
ok single line: '149569'
Test #24:
score: 0
Accepted
time: 24ms
memory: 5332kb
input:
100000 1000000000 228793286 954651636 707393959 122974618 5424005 364103452 202632239 555756179 864598068 604579604 301092261 117217184 961707111 673214921 371252093 375244593 360829673 799484676 60097757 212580587 767239816 270840411 504266799 627091475 356116805 633589406 278635986 22752128 643985...
output:
1560173822
result:
ok single line: '1560173822'
Test #25:
score: 0
Accepted
time: 13ms
memory: 5236kb
input:
100000 100000 29723 23534 51646 9033 85310 23854 94158 49783 69013 44999 68009 13783 1111 7483 42386 91363 84040 63899 40927 78599 3963 48853 75514 55314 49806 28151 65935 18680 82366 94160 36800 94822 91818 92179 85246 37644 98420 11297 25304 1313 74657 90318 74331 77449 24041 50212 20388 64034 693...
output:
151920
result:
ok single line: '151920'
Test #26:
score: 0
Accepted
time: 13ms
memory: 5260kb
input:
100000 1000000000 126675903 518545898 582655716 667277924 74525807 206585371 33807352 554580265 766400642 650167703 578637715 248681164 900425957 585131780 3957608 581518034 459481822 187998672 931791749 38101595 520022334 713505994 405335599 794036150 835433658 459385304 449665702 292770374 5325202...
output:
1491024155
result:
ok single line: '1491024155'
Test #27:
score: 0
Accepted
time: 9ms
memory: 5284kb
input:
100000 100000 64375 15755 84414 70874 67634 46882 19532 55291 57207 45847 0 0 0 0 0 0 0 0 0 0 89771 89137 57685 47875 21589 94762 88423 1569 78852 89741 75256 77909 84071 34334 61739 52771 54788 14167 14767 4395 37625 56713 89262 10934 5695 45413 29704 31055 63719 356 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
155239
result:
ok single line: '155239'
Test #28:
score: 0
Accepted
time: 10ms
memory: 5328kb
input:
100000 1000000000 0 0 0 0 0 0 385756216 325437740 0 0 0 0 0 0 0 0 0 0 607523611 695299215 0 0 0 0 0 0 0 0 0 0 889167196 842787941 163723338 305093456 741138109 695517197 0 0 0 0 0 0 961188410 47205172 139558380 204590885 544183157 284702500 831880886 418433487 0 0 0 0 0 0 0 0 0 0 0 0 210806312 50634...
output:
1521653804
result:
ok single line: '1521653804'
Test #29:
score: 0
Accepted
time: 9ms
memory: 5300kb
input:
100000 50000 3164 8731 2173 8408 1338 1069 9485 9914 3165 9450 2301 7342 5292 9660 1739 1925 4538 7539 4836 8650 6112 3384 9002 2233 194 7183 369 3478 9358 613 3394 1132 9174 3438 3752 4238 8462 5463 5093 2323 1204 5766 5156 705 377 8280 8742 6407 2459 1781 4432 4726 1320 8394 3722 4730 1209 5937 16...
output:
999991706
result:
ok single line: '999991706'
Test #30:
score: 0
Accepted
time: 5ms
memory: 5252kb
input:
100000 50000 5389 5962 9820 4112 1508 6414 5246 2819 4280 8511 839 8851 2667 8045 7956 4442 2284 2095 9339 4852 4792 3709 8913 5516 677 5236 9436 1624 277 384 1487 2427 3738 1373 487 5183 3993 8342 8620 2478 5980 3149 8440 367 1069 5187 1511 5178 876 4939 3902 7587 3259 1719 5568 5265 3022 9497 9524...
output:
999991381
result:
ok single line: '999991381'
Test #31:
score: 0
Accepted
time: 0ms
memory: 5168kb
input:
100000 50000 4953 8567 3830 5132 423 7825 6064 8189 7796 5619 1745 529 8445 401 4598 68 3678 9510 4592 5250 5899 6952 8535 4850 6005 8138 4039 4211 885 8547 9289 9916 2052 3709 8093 5223 6645 384 3197 6564 7293 8829 3300 6500 3087 1372 4612 718 9644 999 7851 3061 5028 2606 2258 2015 9671 6282 3630 2...
output:
999991460
result:
ok single line: '999991460'
Test #32:
score: 0
Accepted
time: 0ms
memory: 5340kb
input:
100000 50000 2171 9134 1218 9664 8003 6181 1221 7866 6061 6202 4706 8015 5894 6364 1088 7374 9519 7962 5342 2240 6806 5563 7440 9148 9518 5830 1757 4063 1589 2232 4957 7581 6616 5257 3197 9836 5130 4766 3496 4541 8635 4130 9410 1458 2381 7943 1923 2190 7833 3642 5699 5687 1358 5811 5379 9075 7689 15...
output:
999991343
result:
ok single line: '999991343'
Test #33:
score: 0
Accepted
time: 10ms
memory: 5220kb
input:
100000 50000 6412 9258 6334 2515 2794 2797 302 1237 4219 1552 2286 8377 988 3357 7263 4708 4089 5272 261 9251 9278 6393 7178 1868 237 153 7011 6126 5761 1275 7214 8713 136 2167 5764 7988 7400 8244 3122 7062 3480 8975 971 6026 2904 6730 4297 49 2000 9004 8435 9841 5446 2428 6758 602 2167 3207 7245 64...
output:
999992504
result:
ok single line: '999992504'
Test #34:
score: 0
Accepted
time: 2ms
memory: 5240kb
input:
100000 50000 1653 7085 8926 5682 1207 7219 5301 149 6048 8504 1413 7541 3374 9640 3900 8915 201 3504 889 8048 1531 5703 1705 8068 6732 1798 2296 2530 4800 682 9799 8735 7346 5863 3245 9444 7394 2746 8799 5987 4856 7529 7241 8817 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 0 1000...
output:
999990713
result:
ok single line: '999990713'
Test #35:
score: 0
Accepted
time: 10ms
memory: 5340kb
input:
100000 50000 0 1000000000 0 1000000000 0 1000000000 0 1000000000 2356 6058 4020 3399 7339 3498 8749 5998 8876 605 6540 2951 0 1000000000 0 1000000000 0 1000000000 0 1000000000 4461 2973 4390 5797 3415 8074 2872 2122 0 1000000000 8898 6266 8167 9915 5998 7041 1533 7726 7997 6676 8903 6500 1524 582 0 ...
output:
999987934
result:
ok single line: '999987934'
Test #36:
score: 0
Accepted
time: 7ms
memory: 5296kb
input:
100000 100000 42570 28461 74595 56533 20759 43114 7630 44058 91094 10155 1038 40219 5782 87572 59568 4115 69810 22848 69266 51213 94525 62069 44241 35639 81478 29772 7123 18105 30788 17552 83102 34809 18403 2073 40753 27913 81720 57358 85070 40326 96166 96080 24645 86305 48589 14500 16670 2772 280 5...
output:
999999835
result:
ok single line: '999999835'