CT55133

Petra Counts the scrolls

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the cotton rows of Whitewick opens only for a perfect tally of scrolls. Petra means to find out. Task: Print the number of index pairs (i,j), i<j, with a[i]+a[j] <= k. Input format: First line: n and k. Second line: n integers. Output format: Print the pair count (fits 64-bit). Constraints: 2 <= n <= 1452; 0 <= a[i],k <= 1000.

Example 1:

Input: 156 825 819 275 113 288 833 946 383 147 407 444 195 644 155 769 864 523 704 500 613 500 5 658 874 416 463 390 78 881 845 722 88 785 767 936 32 177 251 783 862 634 548 434 484 180 1 532 191 741 660 198 739 450 291 844 589 302 435 734 148 419 590 310 366 680 292 589 330 388 466 472 347 394 430 410 328 924 483 975 900 110 641 85 558 610 288 105 881 777 953 538 834 372 390 206 294 249 685 514 633 391 734 146 14 695 510 750 788 682 873 173 191 38 508 88 847 387 492 352 915 304 48 321 870 753 253 54 753 246 986 362 919 300 516 908 887 343 21 954 83 958 242 403 36 66 122 183 260 505 761 941 225 36 465 372 838 352
Output: 4503

Example 2:

Input: 993 1508 636 686 540 680 817 811 548 781 785 775 181 610 240 841 601 624 363 700 119 886 146 805 326 337 755 111 746 513 678 767 679 705 331 693 145 490 12 981 594 157 506 570 304 977 625 667 643 275 986 738 369 905 385 241 467 812 369 308 5 986 391 625 17 801 514 156 114 398 807 431 651 121 634 448 314 734 585 932 557 57 676 509 509 502 207 299 33 360 277 502 757 649 141 384 528 167 989 161 226 373 300 742 255 348 86 924 283 727 556 277 636 47 550 708 868 40 970 133 301 407 42 676 567 33 692 151 323 798 358 574 691 987 344 573 237 124 362 253 129 252 843 643 755 130 120 363 188 395 418 369 647 320 825 735 129 776 652 744 846 672 173 159 382 37 497 135 233 354 175 664 37 130 770 753 692 903 504 313 796 218 771 541 647 710 661 487 267 353 992 184 927 258 701 14 280 770 324 458 853 916 89 43…
Output: 436307

Example 3:

Input: 1143 872 269 309 539 223 291 693 887 833 136 511 492 375 788 960 227 916 501 967 818 25 688 431 535 840 746 989 860 610 313 489 167 694 7 831 269 79 958 217 632 716 451 575 303 8 427 57 589 935 530 420 494 268 334 884 897 727 256 992 696 396 771 790 270 709 350 98 203 319 185 689 368 610 674 282 232 118 873 64 818 311 431 731 20 979 813 157 328 819 796 222 413 901 382 463 240 221 248 808 227 657 323 449 76 884 279 587 574 356 179 416 946 970 146 813 20 827 978 578 611 53 519 404 317 924 695 358 447 473 488 117 285 722 56 96 66 250 735 416 650 462 837 229 646 359 651 133 62 158 513 186 661 162 877 295 207 732 236 782 48 941 699 317 376 76 15 473 544 566 1 703 874 577 189 904 795 199 402 649 276 600 893 323 536 518 746 671 210 991 827 84 277 21 164 269 511 472 608 481 611 860 170 142 917 47 …
Output: 249342

Constraints:

2 <= n <= 1452; 0 <= a[i],k <= 1000.

Loading...
Test Cases:No test cases
No test cases available.