QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#426490 | #1961. Postman | namelessgugugu | AC ✓ | 63ms | 23876kb | C++14 | 4.1kb | 2024-05-31 12:43:30 | 2024-05-31 12:43:30 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <array>
#include <utility>
#include <queue>
#include <cmath>
#include <functional>
#define fileio(PATH) (freopen(PATH ".in", "r", stdin), freopen(PATH ".out", "w", stdout))
using std::vector, std::array, std::pair, std::priority_queue;
using ll = long long;
using ull = unsigned long long;
const ll INF = 0x3f3f3f3f3f3f3f3f;
struct DbHeap
{
priority_queue<ll> st;
priority_queue<ll, vector<ll>, std::greater<ll>> ed;
ll sum;
void push(ll x)
{
if(st.size() && st.top() >= x)
st.push(x), sum += x;
else
ed.push(x);
return;
}
ll prefix_sum(int k)
{
while((int)st.size() < k)
{
ll x = ed.top();
ed.pop();
st.push(x);
sum += x;
}
while((int)st.size() > k)
{
ll x = st.top();
st.pop();
ed.push(x);
sum -= x;
}
return sum;
}
};
vector<ll> solve_core(vector<ll> x, int a, int b)
{
int n = x.size();
vector<ll> res(n, INF);
DbHeap cur = {};
for(int i = 0, now = 0;i < n;++i)
if(x[i] > 0)
{
++now;
ll bas = 2 * x[n - 1] - x[0] - x[i] + std::abs(x[0]);
res[i] = bas + 2 * cur.prefix_sum(std::max(0, now - b));
if(i > 0 && x[i - 1] > 0)
cur.push(x[i] - x[i - 1]);
}
return res;
}
vector<ll> solve(vector<ll> x, int a, int b)
{
int n = x.size();
if(a > b)
{
std::reverse(x.begin(), x.end());
std::swap(a, b);
for(int i = 0;i < n;++i)
x[i] = -x[i];
vector<ll> res = solve(x, a, b);
std::reverse(res.begin(), res.end());
return res;
}
vector<ll> res(n, INF);
if(a == 0)
{
if(x[0] > 0)
res[n - 1] = x[n - 1];
return res;
}
else if(a == 1)
{
if(x[0] > 0)
{
for(int i = 0;i < n - 2;++i)
res[n - 1] = std::min(res[n - 1], x[n - 1] + 2 * (x[i + 1] - x[i]));
for(int i = 0;i < n - 1;++i)
res[i] = 2 * x[n - 1] - x[i];
}
else
{
res[n - 1] = x[n - 1] - 2 * x[0];
for(int i = 0;i < n - 1;++i)
if(x[i + 1] > 0)
res[i] = 2 * (x[n - 1] - x[0]) + x[i];
}
return res;
}
res = solve_core(x, a, b);
std::reverse(x.begin(), x.end());
std::swap(a, b);
for(int i = 0;i < n;++i)
x[i] = -x[i];
vector<ll> res2 = solve_core(x, a, b);
std::reverse(res2.begin(), res2.end());
for(int i = 0;i < n;++i)
res[i] = std::min(res[i], res2[i]);
return res;
}
int main(void)
{
// fileio("postman");
int n, a, b, ty;
scanf("%d%d%d", &n, &a, &ty), b = n - a;
vector<ll> x(n);
for(int i = 0;i < n;++i)
scanf("%lld", &x[i]);
if(n == 1)
ty = 1;
if(ty == 1)
{
std::sort(x.begin(), x.end());
vector<ll> res = solve(x, a, b);
ll ans = *std::min_element(res.begin(), res.end());
printf("%lld\n", ans == INF ? -1ll : ans);
}
else
{
vector<ll> y = x;
y.pop_back();
std::sort(y.begin(), y.end());
ll ans = INF;
if(a > 0)
{
vector<ll> res = solve(y, a - 1, b);
for(int i = 0;i < n - 1;++i)
if(res[i] != INF && y[i] > x[n - 1])
ans = std::min(ans, res[i] + y[i] - x[n - 1]); //, fprintf(stderr, "%d %lld\n", i, res[i] + y[i] - x[n - 1]);
}
if(b > 0)
{
vector<ll> res = solve(y, a, b - 1);
for(int i = 0;i < n - 1;++i)
if(res[i] != INF && y[i] < x[n - 1])
ans = std::min(ans, res[i] + x[n - 1] - y[i]); //, fprintf(stderr, "%d %lld\n", i, res[i] - y[i] + x[n - 1]);
}
printf("%lld\n", ans == INF ? -1ll : ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4096kb
input:
100 0 1 751 558 131 292 317 886 785 847 224 668 649 358 725 250 953 65 176 733 461 84 114 977 628 673 798 863 373 827 51 630 518 347 527 876 366 241 452 670 813 314 846 342 357 460 985 581 841 843 282 907 327 656 411 944 421 99 441 388 568 763 167 351 793 916 517 109 999 390 272 639 513 534 304 253 ...
output:
999
result:
ok single line: '999'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
100 50 1 654 349 533 94 619 754 498 939 469 518 3 661 431 214 195 198 989 548 561 312 262 629 807 981 624 639 178 765 706 782 888 611 553 363 336 91 176 485 735 791 596 455 390 760 995 202 417 82 798 883 209 155 725 908 789 56 49 899 231 423 815 228 314 400 748 946 736 840 385 446 938 284 10 917 593...
output:
1397
result:
ok single line: '1397'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
100 99 1 266 337 80 671 358 778 217 288 219 48 863 19 137 987 602 415 155 398 753 956 210 317 94 303 997 192 123 442 666 959 685 71 34 588 615 214 327 881 582 51 646 630 291 354 749 108 984 308 813 182 384 699 114 692 611 296 590 432 103 240 341 465 969 370 771 914 250 656 742 708 174 323 939 493 17...
output:
1986
result:
ok single line: '1986'
Test #4:
score: 0
Accepted
time: 0ms
memory: 4060kb
input:
100 100 1 713 172 634 763 181 502 78 995 598 751 792 961 585 335 952 343 375 627 651 515 856 121 743 931 18 492 726 517 136 143 314 993 80 29 283 427 248 274 114 200 535 94 174 782 818 90 806 88 104 808 910 892 791 462 304 676 67 973 901 891 705 567 475 444 949 846 299 735 233 914 803 27 810 210 396...
output:
-1
result:
ok single line: '-1'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
100 0 1 -102 -827 -638 -660 -604 -258 -692 -237 -927 -371 -129 -908 -830 -229 -585 -364 -103 -58 -975 -153 -563 -17 -201 -443 -56 -560 -606 -45 -891 -331 -349 -420 -266 -219 -482 -716 -51 -723 -876 -211 -121 -63 -814 -239 -937 -541 -74 -69 -334 -42 -227 -479 -571 -137 -913 -885 -525 -475 -930 -405 -...
output:
-1
result:
ok single line: '-1'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3880kb
input:
100 1 1 -747 -27 -215 -283 -833 -584 -531 -295 -636 -725 -100 -506 -108 -426 -574 -305 -919 -207 -540 -770 -264 -67 -388 -444 -77 -778 -474 -957 -706 -467 -438 -245 -240 -228 -40 -523 -803 -669 -198 -11 -740 -911 -990 -604 -236 -628 -864 -897 -440 -789 -874 -941 -153 -1 -52 -345 -819 -480 -731 -612 ...
output:
1979
result:
ok single line: '1979'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3880kb
input:
100 50 1 -220 -474 -778 -792 -88 -62 -252 -742 -147 -2 -119 -575 -583 -434 -753 -425 -427 -266 -419 -344 -44 -470 -79 -28 -38 -621 -506 -821 -363 -423 -960 -272 -608 -728 -482 -392 -194 -958 -395 -712 -97 -867 -34 -499 -101 -777 -895 -200 -269 -528 -283 -972 -157 -378 -561 -90 -359 -439 -412 -72 -87...
output:
1433
result:
ok single line: '1433'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3748kb
input:
100 100 1 -100 -438 -107 -887 -504 -162 -557 -696 -551 -955 -634 -230 -109 -3 -754 -669 -775 -685 -517 -137 -80 -419 -207 -131 -554 -26 -864 -981 -282 -925 -704 -457 -186 -975 -730 -174 -294 -176 -664 -385 -625 -894 -93 -156 -737 -541 -265 -906 -403 -445 -41 -260 -609 -828 -60 -800 -750 -6 -239 -846...
output:
981
result:
ok single line: '981'
Test #9:
score: 0
Accepted
time: 41ms
memory: 20648kb
input:
300000 299900 1 975494913 919276412 971822415 306295652 981185393 751782065 954706942 908207836 981200361 32580760 933121007 333012429 165323270 996792016 391102892 389040132 322687143 812406210 317257318 897931477 984765477 903680189 380567163 385513860 359332788 768879270 959852716 843574823 40665...
output:
2999995655
result:
ok single line: '2999995655'
Test #10:
score: 0
Accepted
time: 45ms
memory: 20724kb
input:
300000 299998 1 909963807 988052984 968956733 -4808472 902213296 920535913 892118351 827900769 961754681 767948569 999500834 260018295 349443084 916399438 810195269 870433267 998221337 976774994 721697345 309230801 868119413 986186795 839916169 968333430 270886226 972109273 970633299 744019611 94687...
output:
2999982764
result:
ok single line: '2999982764'
Test #11:
score: 0
Accepted
time: 54ms
memory: 19536kb
input:
300000 199998 1 760358089 791244679 984736604 275806750 247939634 978615072 302237434 991049550 934591187 382618436 230786914 789192758 236573159 396652403 855918715 877242673 984062779 458214751 395632321 988479643 399571663 377064418 969391408 796094553 999200405 268953105 991121067 941437116 8161...
output:
2999990891
result:
ok single line: '2999990891'
Test #12:
score: 0
Accepted
time: 38ms
memory: 20652kb
input:
300000 159999 1 942199382 341392725 348398313 975348962 960975251 991959712 53847869 626494403 440799630 834310895 400767959 364210160 292487754 970542288 975196994 411308866 985283714 134051724 395718459 725662488 484999687 920311363 991679253 970656922 988945259 265707789 986990069 925538439 21784...
output:
2999991601
result:
ok single line: '2999991601'
Test #13:
score: 0
Accepted
time: 49ms
memory: 17052kb
input:
300000 19999 1 816144624 978397453 440665138 283612424 945098204 339820332 885340682 313718676 922094581 381702751 471032137 872210762 240663640 985886109 780872483 996469198 325835675 968745840 794294823 121382252 948969054 880827421 977238043 126375169 950327749 994803525 201684720 219097101 41030...
output:
2999973677
result:
ok single line: '2999973677'
Test #14:
score: 0
Accepted
time: 44ms
memory: 18384kb
input:
300000 100 1 -989312886 26761301 -985728917 -391478114 -78077877 -953591083 -952597776 -966592009 -374175692 -972714759 -865102046 -253636908 -864766148 -877082592 -985097949 -955548975 -946513709 -939137884 -856158829 -878136428 -845660452 -236979816 -198429617 -194522362 -881227475 -934250481 -955...
output:
2999995006
result:
ok single line: '2999995006'
Test #15:
score: 0
Accepted
time: 47ms
memory: 18084kb
input:
300000 2 1 -204526971 -679003931 -270259823 -998170158 -517990818 -331521849 -806999125 -884402567 -394558999 -938154172 -881759024 -205775904 -989396335 -323846513 -902520693 -105353949 -989729701 -999109123 -958206886 -306635474 -650621491 -980044442 -238027623 -916877077 -987985082 -888733152 -92...
output:
2999989700
result:
ok single line: '2999989700'
Test #16:
score: 0
Accepted
time: 51ms
memory: 17048kb
input:
300000 100002 1 -982563248 -884271825 -991717692 -66746774 -387604370 -989101502 -921822473 -452835479 -343905539 -982352212 -334927349 -951113204 -975955017 -816967163 -951729538 -694131066 -367658474 -933012591 -276245389 -456156314 -309453648 -818983958 -832001600 -247724435 -401778387 -287758829...
output:
2999985866
result:
ok single line: '2999985866'
Test #17:
score: 0
Accepted
time: 41ms
memory: 18128kb
input:
300000 140001 1 -981316007 -209123045 -183025883 -382483756 -958956835 -981127429 -996221336 -953952589 -904879391 -283899126 -828187571 -206037038 -961803343 -987393716 -953516223 -348983568 -927817660 281748110 -999551602 -96518828 -400608671 31532273 -872389194 -322196531 -852614563 -441246454 -2...
output:
2999993311
result:
ok single line: '2999993311'
Test #18:
score: 0
Accepted
time: 50ms
memory: 19400kb
input:
300000 280001 1 -913709302 -903985908 -940299999 -205921103 -885171614 -92135108 -977947386 -988415908 -320447615 -795241235 -999358836 -984300628 -406654796 -479470316 -415791878 -966100008 -978511377 -301932359 -356529615 -997674923 -876662022 -887931627 -435841697 -996688996 -985518116 -992611953...
output:
2999990077
result:
ok single line: '2999990077'
Test #19:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
201 0 2 813 958 277 425 585 853 243 463 433 999 890 615 984 992 363 704 962 349 822 629 44 836 3 832 214 127 816 106 560 570 693 40 934 910 310 674 508 930 995 982 761 429 329 283 602 312 190 67 29 531 847 267 480 956 225 592 466 527 343 809 206 633 364 202 951 581 808 460 940 610 821 725 745 846 12...
output:
-1
result:
ok single line: '-1'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3868kb
input:
201 1 2 641 284 624 715 55 416 598 109 896 957 102 777 343 933 263 245 488 444 65 493 860 504 595 98 856 685 358 523 434 882 835 497 785 526 531 272 781 101 535 501 207 510 945 41 214 770 556 314 87 522 361 517 513 815 969 847 919 867 779 333 727 908 811 228 857 4 153 441 198 419 437 515 664 113 394...
output:
1484
result:
ok single line: '1484'
Test #21:
score: 0
Accepted
time: 0ms
memory: 3776kb
input:
201 2 2 459 848 667 178 587 393 240 592 679 43 323 670 473 484 844 988 243 40 644 657 786 870 33 521 183 523 631 696 701 572 281 306 912 886 915 961 549 538 739 941 706 712 820 506 881 916 266 69 860 84 54 677 945 370 773 681 733 800 312 296 50 953 671 794 356 188 190 390 831 542 433 210 398 57 874 ...
output:
1491
result:
ok single line: '1491'
Test #22:
score: 0
Accepted
time: 0ms
memory: 4092kb
input:
201 100 2 325 812 770 920 500 742 868 298 47 240 521 458 250 991 396 413 314 618 11 192 704 188 187 781 948 611 115 360 890 662 373 612 776 479 368 766 108 209 926 799 636 539 701 762 579 455 312 747 306 21 691 687 904 974 852 994 140 380 625 614 347 29 519 571 518 431 543 914 385 791 765 559 617 27...
output:
1514
result:
ok single line: '1514'
Test #23:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
201 101 2 363 662 422 678 921 302 192 43 813 948 288 849 3 993 119 59 587 56 605 729 265 42 77 281 417 160 832 717 520 150 379 705 415 106 359 759 507 820 15 523 29 826 37 392 864 140 10 997 767 633 204 498 102 467 447 370 736 439 703 685 535 963 646 928 529 33 816 68 7 566 198 831 752 896 651 593 1...
output:
1498
result:
ok single line: '1498'
Test #24:
score: 0
Accepted
time: 0ms
memory: 4060kb
input:
201 0 2 -706 735 631 -970 -867 -945 99 -987 -930 -335 -157 -610 464 -357 -27 988 501 -528 -739 774 -443 540 876 -862 26 -244 344 453 178 -437 295 -95 -812 361 360 -747 889 -842 641 811 226 -776 420 -293 519 718 518 736 -462 617 -215 836 -822 -582 -472 -239 -653 -525 -990 -836 858 -403 308 270 803 -7...
output:
-1
result:
ok single line: '-1'
Test #25:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
201 1 2 -127 -217 -571 -295 618 -626 871 253 886 -632 131 -863 785 -789 -706 111 -598 -496 -116 -246 -901 -94 -122 322 783 498 -831 247 415 -918 156 -805 94 -18 -319 671 495 -521 -407 595 782 -278 690 -719 -340 552 966 -317 -248 -408 521 217 -497 -971 465 852 798 -397 280 803 -400 -739 -604 980 790 ...
output:
2986
result:
ok single line: '2986'
Test #26:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
201 5 2 -389 505 -693 -810 804 246 -880 -847 266 145 118 361 289 -457 318 -67 522 -207 -844 343 194 -662 621 90 -253 -242 850 816 211 -824 400 -674 -214 -278 767 -137 161 -229 -917 -621 -571 539 800 -198 129 -922 112 479 724 -461 -631 967 -549 972 -12 30 711 -735 558 21 662 936 -362 -957 892 367 -21...
output:
2969
result:
ok single line: '2969'
Test #27:
score: 0
Accepted
time: 0ms
memory: 4064kb
input:
201 199 2 271 -122 -574 116 -482 942 840 138 -962 -546 800 861 -501 -552 -970 -108 -768 -288 -136 82 -861 -698 843 -177 823 814 -55 -603 -70 489 -275 -427 -401 -788 -859 -317 -904 107 -887 -250 892 -651 666 -778 -7 -210 -588 -566 -669 482 -129 263 789 -468 -110 -13 763 392 740 -274 -469 597 670 -239...
output:
4862
result:
ok single line: '4862'
Test #28:
score: 0
Accepted
time: 0ms
memory: 3868kb
input:
201 200 2 -997 881 -394 71 794 606 199 -273 -755 -579 892 -140 668 228 -271 -258 -113 -415 -25 536 -159 508 -505 767 -748 238 -642 -861 -501 -773 859 935 443 596 771 953 -727 -229 92 -465 853 -939 -963 -173 992 89 -84 220 981 615 -794 570 316 -647 141 225 -221 -267 -503 -818 -47 344 562 726 368 -657...
output:
-1
result:
ok single line: '-1'
Test #29:
score: 0
Accepted
time: 0ms
memory: 3744kb
input:
201 0 2 352 241 -342 297 -509 873 -959 660 -468 159 -436 287 331 785 -684 -723 280 -979 -554 827 -473 171 617 204 -835 790 411 114 -84 928 -908 544 284 -552 -617 -582 447 -11 -568 -536 -56 545 -128 229 417 907 533 50 -874 -920 974 -256 480 134 404 868 -480 43 875 -99 174 -292 482 -973 -223 270 751 -...
output:
-1
result:
ok single line: '-1'
Test #30:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
201 1 2 871 -413 -995 930 -970 967 -24 277 820 -722 -541 -20 219 -353 -442 -762 208 91 13 485 -479 -176 229 595 -237 -599 622 276 -928 -875 492 747 425 753 183 -511 -507 -472 -470 841 25 -828 768 420 51 -276 -865 -211 -467 -977 98 727 -415 -884 673 -277 137 443 974 -539 -316 -258 665 921 -453 951 -5...
output:
3986
result:
ok single line: '3986'
Test #31:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
201 2 2 845 500 -175 13 -87 44 -837 -841 -868 -856 706 -671 -161 746 878 248 -486 821 97 -464 221 -171 126 -702 -694 681 240 108 -455 -526 -591 -393 -482 625 627 573 353 423 -275 -270 169 -813 -150 207 -282 498 5 768 -790 -157 -872 985 970 -935 711 -220 233 320 48 185 490 -376 -627 -931 -940 887 -54...
output:
3911
result:
ok single line: '3911'
Test #32:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
201 3 2 -680 -833 -217 -231 491 -203 954 -565 693 559 -186 457 477 942 -310 -787 -573 343 66 981 461 67 -475 -39 -542 -719 -112 534 -968 -812 -550 627 643 878 -624 284 -954 -697 605 639 -158 96 673 218 521 -226 -632 88 -490 399 -689 201 -931 -249 504 835 736 580 -57 171 -529 -323 -531 -582 787 -410 ...
output:
3981
result:
ok single line: '3981'
Test #33:
score: 0
Accepted
time: 0ms
memory: 4096kb
input:
201 200 2 597 -727 946 503 409 227 859 700 512 -872 -556 -758 982 -445 -183 -974 -416 371 201 971 867 -607 217 -774 -43 -803 432 -813 -619 384 168 520 131 -96 -562 765 -782 546 -701 100 -751 -694 -535 -741 605 49 -44 -265 -53 -516 -662 775 -242 208 574 -390 -292 799 856 288 735 232 494 -580 -360 -71...
output:
3933
result:
ok single line: '3933'
Test #34:
score: 0
Accepted
time: 0ms
memory: 4064kb
input:
201 201 2 352 -630 690 -242 -6 179 -56 257 34 153 -503 925 -146 -644 -77 -36 -616 -259 388 -336 425 -271 819 198 724 846 -173 937 204 305 216 -674 637 612 343 -34 -255 610 -49 -115 236 329 859 839 -471 -321 -513 -553 -144 -750 738 396 108 470 25 -982 734 358 -936 -946 -332 -296 -582 -845 899 922 -64...
output:
-1
result:
ok single line: '-1'
Test #35:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
101 0 2 348 845 522 766 255 580 905 978 622 847 367 412 394 693 996 164 18 299 823 227 31 984 867 62 557 781 831 594 214 144 496 122 471 97 283 381 598 737 374 154 747 423 451 565 630 890 85 959 972 812 187 116 529 389 646 927 502 692 803 727 206 40 104 584 232 669 213 270 595 716 953 515 534 333 99...
output:
-1
result:
ok single line: '-1'
Test #36:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
101 1 2 473 354 885 32 24 727 884 404 686 654 6 579 774 520 551 643 581 896 943 150 883 235 236 576 400 105 790 64 206 704 298 134 736 661 320 492 255 36 112 676 598 756 28 563 141 720 361 274 388 747 926 266 628 346 949 443 671 465 480 843 381 679 876 341 580 510 63 966 998 689 955 54 327 399 307 9...
output:
1994
result:
ok single line: '1994'
Test #37:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
101 100 2 408 946 286 231 685 614 71 895 569 531 229 797 996 697 485 150 612 43 434 215 679 287 370 314 514 172 501 821 121 473 277 938 540 832 609 854 789 930 183 518 475 640 155 672 559 340 481 580 88 397 29 14 728 56 958 48 213 551 424 352 309 344 660 751 60 899 691 368 419 221 737 701 376 875 79...
output:
1985
result:
ok single line: '1985'
Test #38:
score: 0
Accepted
time: 0ms
memory: 3748kb
input:
101 101 2 241 891 700 877 527 542 410 917 425 256 829 259 201 108 384 894 648 84 780 729 626 26 174 311 881 70 110 621 264 512 42 704 145 456 676 843 251 565 428 535 981 496 539 696 93 199 203 716 335 794 671 937 180 715 702 346 454 861 615 114 393 903 481 781 75 351 772 596 125 792 563 117 370 60 5...
output:
-1
result:
ok single line: '-1'
Test #39:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
101 0 2 -58 -472 -109 -758 -97 -45 -771 -894 -495 -909 -522 -161 -518 -19 -119 -13 -750 -199 -637 -431 -313 -266 -239 -628 -304 -339 -79 -592 -51 -253 -729 -338 -768 -425 -569 -153 -695 -536 -328 -477 -908 -797 -332 -182 -875 -798 -836 -172 -574 -959 -75 -70 -449 -346 -134 -548 -792 -398 -59 -873 -4...
output:
-1
result:
ok single line: '-1'
Test #40:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
101 1 2 -388 -172 -531 -312 -165 -247 -900 -507 -325 -986 -766 -529 -527 -114 -162 -181 -662 -670 -347 -378 -365 -209 -156 -852 -792 -58 -906 -17 -656 -120 -572 -293 -21 -552 -258 -883 -123 -865 -228 -888 -161 -395 -605 -401 -845 -997 -199 -149 -727 -976 -66 -757 -80 -427 -934 -508 -331 -455 -73 -25...
output:
2127
result:
ok single line: '2127'
Test #41:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
101 100 2 -382 -31 -984 -482 -56 -519 -29 -176 -272 -140 -209 -522 -375 -685 -469 -907 -111 -503 -107 -317 -371 -637 -313 -999 -766 -15 -834 -36 -582 -894 -636 -185 -742 -263 -355 -961 -400 -577 -952 -916 -408 -757 -191 -1 -962 -279 -154 -979 -48 -502 -25 -935 -46 -286 -776 -114 -797 -592 -840 -779 ...
output:
2865
result:
ok single line: '2865'
Test #42:
score: 0
Accepted
time: 0ms
memory: 4064kb
input:
101 101 2 -781 -386 -847 -660 -212 -769 -305 -858 -262 -369 -833 -282 -1 -981 -255 -761 -986 -841 -526 -768 -104 -938 -184 -936 -904 -872 -315 -173 -824 -227 -635 -715 -492 -779 -886 -270 -990 -166 -265 -751 -913 -497 -94 -609 -474 -714 -550 -563 -499 -90 -695 -345 -692 -947 -42 -597 -801 -435 -951 ...
output:
-1
result:
ok single line: '-1'
Test #43:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
101 0 2 686 254 895 481 784 384 327 669 722 242 837 813 241 129 774 918 799 909 778 976 155 924 232 509 114 741 528 294 649 494 483 12 230 221 657 404 469 265 888 807 564 321 546 650 283 185 936 960 344 950 396 697 970 144 489 36 983 877 184 177 615 7 496 633 280 591 549 752 215 456 501 262 517 247 ...
output:
989
result:
ok single line: '989'
Test #44:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
101 1 2 287 48 373 406 178 715 686 234 303 919 357 877 114 398 219 802 201 653 469 740 927 76 776 414 744 990 635 553 940 144 132 259 764 536 959 865 438 153 210 529 619 401 693 647 666 463 677 767 615 700 361 941 627 148 542 384 756 157 981 857 743 545 465 323 942 416 491 610 430 238 567 89 439 558...
output:
1000
result:
ok single line: '1000'
Test #45:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
101 100 2 489 757 537 524 131 183 175 124 287 450 913 844 939 509 76 496 480 618 553 378 694 894 338 86 606 708 945 966 859 585 263 559 37 115 354 300 924 107 295 448 867 244 436 552 699 366 931 673 685 215 733 494 652 675 650 389 70 796 802 887 775 40 507 256 224 444 114 16 990 672 943 750 237 883 ...
output:
-1
result:
ok single line: '-1'
Test #46:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
101 101 2 342 125 40 782 741 951 522 353 764 946 130 787 761 64 518 300 187 880 465 738 108 495 101 620 362 796 213 493 13 633 573 920 579 915 332 884 59 686 651 900 566 445 654 285 958 417 27 256 388 807 705 700 826 169 7 537 913 501 128 318 327 544 934 434 894 452 723 179 247 626 312 267 146 959 2...
output:
-1
result:
ok single line: '-1'
Test #47:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
101 0 2 183 888 207 840 916 235 898 435 757 801 154 894 148 403 574 944 462 305 285 487 827 850 189 315 924 370 510 323 157 708 375 173 929 122 208 249 836 266 538 107 653 210 911 282 864 722 273 698 889 346 847 298 419 818 50 768 369 356 625 478 996 98 633 695 681 424 336 805 91 647 58 597 725 667 ...
output:
-1
result:
ok single line: '-1'
Test #48:
score: 0
Accepted
time: 0ms
memory: 3740kb
input:
101 1 2 929 694 81 886 789 828 783 117 251 815 29 913 362 906 298 965 12 545 966 524 625 982 685 657 567 651 580 70 344 14 51 488 995 199 588 429 113 875 468 893 133 596 123 960 71 945 749 313 277 507 343 162 226 325 865 776 272 924 93 42 358 791 662 289 480 630 855 768 433 933 947 638 860 972 459 1...
output:
1988
result:
ok single line: '1988'
Test #49:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
101 50 2 367 529 424 972 650 809 22 146 847 125 703 301 69 778 385 825 536 641 29 458 431 43 66 233 963 380 923 638 432 608 686 256 619 419 51 270 813 792 876 409 656 616 288 976 264 248 938 476 50 513 320 42 190 669 787 836 573 294 840 603 666 622 765 736 677 372 770 793 340 359 590 704 449 905 138...
output:
1947
result:
ok single line: '1947'
Test #50:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
101 100 2 975 284 258 974 58 949 719 458 631 265 891 915 627 576 86 173 247 400 501 900 884 876 215 828 231 831 991 207 343 745 22 110 233 695 809 777 123 686 95 7 616 382 410 351 823 359 857 31 304 732 484 179 431 556 208 73 670 167 589 274 609 518 999 794 45 64 927 298 882 17 108 865 632 919 394 9...
output:
1997
result:
ok single line: '1997'
Test #51:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
101 101 2 42 560 563 89 51 375 953 120 102 203 819 188 866 694 158 367 679 229 81 289 484 750 768 18 319 859 725 26 748 831 766 848 78 328 15 647 180 286 331 295 362 531 196 650 913 512 383 24 658 570 938 493 496 919 526 901 132 539 653 899 282 791 685 970 455 631 740 633 174 262 447 226 518 222 39 ...
output:
-1
result:
ok single line: '-1'
Test #52:
score: 0
Accepted
time: 36ms
memory: 21068kb
input:
300000 2 2 952657389 978830664 964464215 990244896 285280224 997680811 901160047 286738095 983968972 993410730 420878131 369899431 961694853 422376826 716574146 937612009 892836282 182821075 884840250 428813938 976597525 994824015 993983794 955192370 995664741 369774177 884140966 667573399 968020021...
output:
3755413493
result:
ok single line: '3755413493'
Test #53:
score: 0
Accepted
time: 52ms
memory: 21484kb
input:
300000 50000 2 973286131 203234521 947492813 314737636 456061535 978208823 240451086 924148023 883087950 958410411 995908296 962156218 966738835 894473195 873365505 241601622 370798683 936514233 392829194 992002431 852353920 998459183 404009289 933965018 989804035 403330049 275170266 935414660 31055...
output:
3755739397
result:
ok single line: '3755739397'
Test #54:
score: 0
Accepted
time: 58ms
memory: 22896kb
input:
300000 150000 2 969789033 906483377 939895310 354773056 969306769 950636571 465697190 374761800 648106463 992987479 982642640 794511183 954430350 987367654 319739220 944241880 971456781 411911165 990905371 961290408 377842384 712262012 450780442 965705977 989492831 379317122 176048590 963953141 3628...
output:
3756025931
result:
ok single line: '3756025931'
Test #55:
score: 0
Accepted
time: 54ms
memory: 23316kb
input:
300000 299900 2 974978096 953959736 955398613 270130759 886607880 989550074 432219312 325817899 982220277 951784619 994535921 405667220 959535192 340275954 316639475 994719927 359981193 986670708 963686534 393735664 985633229 297399243 786344668 998493486 276379517 835841385 945140102 392696039 9550...
output:
4243098124
result:
ok single line: '4243098124'
Test #56:
score: 0
Accepted
time: 46ms
memory: 23268kb
input:
300000 299990 2 961640855 365265267 363435407 991955830 225993445 992154406 945921320 995388142 418861227 996210983 755882162 952842370 812438429 903380482 959696467 428779347 140970148 988510829 406418042 974132074 408290119 324756375 299969674 990356549 944172406 382380638 994200622 375069467 9741...
output:
4245180135
result:
ok single line: '4245180135'
Test #57:
score: 0
Accepted
time: 39ms
memory: 21072kb
input:
300000 2 2 933968157 843590236 955598185 802597754 987581827 916677800 382392053 471422460 975779798 373750094 859891389 922418829 968301807 825760719 244452971 915492609 967828397 949215636 995945475 342944509 421959089 227214518 993753976 970896360 436144666 430371999 333218274 876250343 287019788...
output:
1757676316
result:
ok single line: '1757676316'
Test #58:
score: 0
Accepted
time: 56ms
memory: 20796kb
input:
300000 50000 2 416201135 371231161 988348109 851816172 812092361 985015732 408650190 866604886 977139022 988647857 975933384 990340710 929777310 429597535 846146223 369127563 348171178 920583283 995956063 968888115 196262235 348615451 951460109 300598998 978717872 339887362 412809956 983279491 94294...
output:
1757196823
result:
ok single line: '1757196823'
Test #59:
score: 0
Accepted
time: 63ms
memory: 22792kb
input:
300000 150000 2 37351487 454433390 236710766 981542902 403777174 866132033 931264251 813287827 995989620 389950232 995193048 432717191 915890217 948517059 996498544 949714480 903077158 361923611 998705821 986188905 304216751 959849255 957216886 924834248 945214571 209864883 998004693 691779669 91442...
output:
1757183281
result:
ok single line: '1757183281'
Test #60:
score: 0
Accepted
time: 44ms
memory: 23216kb
input:
300000 299900 2 373077692 980274657 932270537 889683882 925241462 399345565 972735199 941761041 262919943 980605051 371618392 991276538 334825858 929765615 971529416 855334104 472283904 91762985 406178835 898110900 414394289 327918045 983691151 439235603 344312734 921452839 289178521 975272124 42974...
output:
2244513141
result:
ok single line: '2244513141'
Test #61:
score: 0
Accepted
time: 61ms
memory: 23876kb
input:
300000 299990 2 631189086 974856109 323468193 279471447 345857868 996285113 997245798 279065398 989953001 411245988 694363830 414821751 411308131 388053039 951719314 224125940 938655306 798902493 878958780 430146129 916110759 940163542 980641738 999601633 909205130 407539441 409745747 349218515 9814...
output:
2246533971
result:
ok single line: '2246533971'
Test #62:
score: 0
Accepted
time: 37ms
memory: 20892kb
input:
300000 2 2 891598 999947 973369 930981 482998 984188 368385 970182 564696 895001 962989 406302 984698 461442 858001 402896 981688 992544 503645 547337 986318 790143 825764 938160 973478 998218 967872 938119 986831 932086 397727 974843 524240 758502 736584 892486 542339 245253 959267 879518 908181 98...
output:
2001691586
result:
ok single line: '2001691586'
Test #63:
score: 0
Accepted
time: 50ms
memory: 20872kb
input:
300000 50000 2 965773 409861 946321 523230 858134 930794 493161 995171 792030 892620 883439 930343 951320 425319 399908 275813 789439 823174 947526 894025 515065 978963 895672 425040 155119 481362 476540 760712 462449 995376 892467 906813 950766 416391 530509 262335 977469 316472 976451 520915 93727...
output:
2001693012
result:
ok single line: '2001693012'
Test #64:
score: 0
Accepted
time: 55ms
memory: 22900kb
input:
300000 150000 2 962167 570076 406979 327866 995573 318933 291225 967752 807978 965914 937823 840750 524719 965739 959482 808848 996434 474039 954312 555131 990241 570741 997953 535268 478531 999175 398614 454610 360332 931424 934781 242319 895078 998741 487198 565620 442241 899268 309239 948974 5151...
output:
2001678517
result:
ok single line: '2001678517'
Test #65:
score: 0
Accepted
time: 47ms
memory: 23296kb
input:
300000 299900 2 454722 984883 372603 466863 922736 982200 443619 488707 326783 901266 939904 976006 929518 376683 485113 871054 841693 320274 428639 473826 428738 518799 843060 995722 83436 988718 395746 990625 936171 962280 906601 927479 920413 169519 999642 978352 571247 404525 971374 975774 95953...
output:
2002300846
result:
ok single line: '2002300846'
Test #66:
score: 0
Accepted
time: 52ms
memory: 23228kb
input:
300000 299990 2 680652 934594 834524 996416 953970 485270 992553 517649 750702 521967 935515 952536 973195 427319 951794 983621 949653 980845 935925 504995 464603 989108 322216 525037 366412 437741 988618 424550 830981 996103 935192 877365 982577 481100 998617 948360 874944 987448 506022 913339 9019...
output:
2002297805
result:
ok single line: '2002297805'
Test #67:
score: 0
Accepted
time: 38ms
memory: 21648kb
input:
300000 299998 2 -992552603 -134570701 -924532714 -926704091 -864092006 -993458455 -889996015 -938566527 -365371366 -982797272 -113905670 -147951308 -985236958 -831269074 -935251815 -988718545 -421753817 -891174734 -980535204 -429152139 -967077941 -978368666 -194032823 -882425705 -984247758 -92362597...
output:
3754876854
result:
ok single line: '3754876854'
Test #68:
score: 0
Accepted
time: 62ms
memory: 23248kb
input:
300000 250000 2 -944190645 -902754040 -447270484 -906560009 -916656276 -378559444 -997123704 -986277800 -902033953 -960312947 -318349115 -284184245 -72322626 -961317228 -435279002 -343874835 -974441742 -966251983 -385229559 -450144398 -993569454 -896004324 -967728664 -696142846 -101279138 -275202038...
output:
3755296035
result:
ok single line: '3755296035'
Test #69:
score: 0
Accepted
time: 58ms
memory: 22956kb
input:
300000 150000 2 -993902693 -460212951 -986315684 -966054162 -371459330 -999903717 -914360917 -997215253 -956625466 -977603549 -996929279 -955558235 -999554130 -993094999 -732298807 -807021973 -992275141 -923164273 -355121928 -985762318 -977535903 -218786063 -238940981 -462461484 -976336847 -96417324...
output:
3755117331
result:
ok single line: '3755117331'
Test #70:
score: 0
Accepted
time: 61ms
memory: 20756kb
input:
300000 100 2 -949688825 -427976800 -430741010 -468415162 -47045672 -767785928 -987576594 -964002779 -437181768 -400292738 -847588608 -999184548 -983207825 -996468382 -338513512 -827631359 -69074657 -939260691 -932994738 -960176270 -865477350 -323797530 -964499254 -860999025 -965269767 -979631223 -93...
output:
4243563218
result:
ok single line: '4243563218'
Test #71:
score: 0
Accepted
time: 47ms
memory: 21356kb
input:
300000 10 2 -457897371 -362546949 -354907935 -968153573 -923913549 -369833065 -442183265 -341807596 -870162616 -955572877 -378989486 -981190196 -427242285 -382741429 -788959611 -331001272 -425554349 -190176076 -439911891 -802369699 -909319152 -967103039 -419397049 -959526141 -331578120 -927883174 -6...
output:
4244027950
result:
ok single line: '4244027950'
Test #72:
score: 0
Accepted
time: 38ms
memory: 21748kb
input:
300000 299998 2 -408766962 -974300486 -357979020 -946303979 -989537752 -954571111 -303753990 -988768137 -909604941 -968686284 -385106744 -593461043 -888202316 -289698625 -936636205 -995179414 -953816522 -366256055 -867643448 -937955307 -966714745 -956789578 -906175406 -372168260 -537519801 -96877208...
output:
1757413541
result:
ok single line: '1757413541'
Test #73:
score: 0
Accepted
time: 58ms
memory: 23284kb
input:
300000 250000 2 -374111193 -410503830 -981174815 -895573981 -960908677 -996462459 -989555261 -339229981 -264588185 -253794758 -960185678 -974668864 -914070297 -848334477 -987851904 -342313311 -387832324 -175133916 -953417154 -310773790 -999892672 -992109378 -403732874 -139924726 -968047561 -99654004...
output:
1757145740
result:
ok single line: '1757145740'
Test #74:
score: 0
Accepted
time: 63ms
memory: 22844kb
input:
300000 150000 2 -993145577 -871715425 -231669209 -410662973 -847614904 -992170469 -890323576 -818849976 -324581587 -392912693 -992850456 -972198432 -965591689 -906458081 -784376050 -407449122 -378877055 -393007532 -303662497 -355056543 -931581060 -439013305 -54790358 -916261963 -428667765 -195748675...
output:
1758102808
result:
ok single line: '1758102808'
Test #75:
score: 0
Accepted
time: 56ms
memory: 20988kb
input:
300000 100 2 -968344642 -947806146 -342605069 -305940571 -992903815 -968610544 -378187514 -431207592 -961209483 -953442072 -996365646 -995938697 -956758032 -921916357 -939552559 -294980410 -396733883 -214223675 -996263240 -991583417 -935133642 -979636871 -175773539 -928979735 -935547964 -369044098 -...
output:
2244556683
result:
ok single line: '2244556683'
Test #76:
score: 0
Accepted
time: 47ms
memory: 20916kb
input:
300000 10 2 -998560426 -406924761 -952878605 -262748364 -996514826 -338270485 -999972725 -968262624 -988128445 -930320477 -946400727 -434895220 -436969109 -391863308 -988929324 -274829369 -376527891 -296635534 -984027352 -426862009 -999113774 -931423490 -989312896 -638370860 -987804712 -338997844 -4...
output:
2246004079
result:
ok single line: '2246004079'
Test #77:
score: 0
Accepted
time: 50ms
memory: 21936kb
input:
300000 299998 2 -478049 -281522 -332224 -964088 -853670 -492252 -909878 -966211 -222418 -433847 -897083 -979171 -997201 -739095 -970622 -966002 -550935 -435354 -889079 -453318 -970310 -967645 -972418 -978060 -956844 -515033 -981908 -965730 -997255 -385709 -595937 -589059 -348033 -933783 -979524 -495...
output:
2001693688
result:
ok single line: '2001693688'
Test #78:
score: 0
Accepted
time: 51ms
memory: 23060kb
input:
300000 250000 2 -985400 -976849 -423424 -932213 -960523 -808969 -882384 -688412 -921034 -944256 -451379 -599792 -983604 -945550 -975248 -431787 -41724 -996597 -938927 -819193 -491795 -936574 -496930 -358224 -520152 -986050 -997585 -359727 -456021 -524597 -955971 -820993 -969591 -968874 -965938 -4420...
output:
2001662915
result:
ok single line: '2001662915'
Test #79:
score: 0
Accepted
time: 56ms
memory: 22896kb
input:
300000 150000 2 -927391 -991405 -752891 -946987 -143084 -926662 -938009 -527714 -554640 -586788 -887702 -953498 -963963 -351254 -447900 -980969 -987747 -903140 -336545 -900113 -968566 -334469 -781581 -520892 -875584 -492984 -976904 -509171 -986233 -986268 -969098 -515211 -987885 -362387 -436567 -533...
output:
2001685396
result:
ok single line: '2001685396'
Test #80:
score: 0
Accepted
time: 50ms
memory: 21504kb
input:
300000 100 2 -448839 -995916 -589394 -984724 -245019 -995057 -983814 -971781 -989953 -312810 -974492 -920158 -797224 -184641 -503035 -960280 -467096 -500666 -925662 -988255 -978408 -529422 -996300 -980968 -610124 -342689 -552135 -404551 -998577 -943752 -541956 -994092 -923008 -575510 -967522 -334057...
output:
2002286946
result:
ok single line: '2002286946'
Test #81:
score: 0
Accepted
time: 48ms
memory: 23292kb
input:
300000 299990 2 853529 445293 905566 917707 561715 985903 438585 954231 952585 955572 958374 370963 976804 578418 398086 506778 406056 331366 974356 843208 429394 478571 956166 372542 861520 926302 917959 956442 949338 985072 957276 511091 982331 489200 919116 991626 979995 468110 472737 489387 9243...
output:
2002284927
result:
ok single line: '2002284927'