CT38786

The ribbons Frugal Pairs Puzzle

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The surveyor Sona has been asked to plan the harvest festival. On the desk lies a long table of ribbons readings. 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 <= 1373; 1 <= a[i],k <= 1000000.

Example 1:

Input: 111 1534621 240226 379317 857273 753806 833541 591939 265952 6767 34772 925124 188310 144649 951412 78431 923650 716217 936693 466469 902089 237548 321690 820281 788633 23750 305797 115722 919095 81467 952008 702777 602538 691881 695813 49845 606222 54917 281777 460560 429640 238221 966193 681197 545487 663644 933836 114506 475177 689932 439258 800281 718233 599740 448385 492927 842204 259326 977857 750160 267060 985074 554520 995363 959494 500937 640605 981153 830152 482855 875671 146653 169265 968064 29588 911711 935149 300738 283459 645735 24562 322136 445113 69887 759915 705308 716505 990443 958828 106694 378063 632154 912132 834564 898614 76741 836772 120085 795168 567302 946360 694479 475299 657893 96994 248597 195909 715252 821274 657413 975461 449568 101899
Output: 4881

Example 2:

Input: 291 443915 61137 551740 831806 926060 660137 599414 224722 731789 388379 402673 323987 52531 812181 891395 736448 168303 330343 480970 119485 385411 133850 292047 495632 294385 38568 29017 146693 412946 210911 673844 876978 120462 967173 488892 356568 986591 507344 576836 809027 76215 24468 356592 800568 685077 945545 684452 831067 462918 806038 917384 307112 341216 401030 221892 31777 788680 533794 589719 214949 219553 586108 684599 510864 553436 850415 529593 434696 79973 757988 633464 281277 284744 965899 450203 544629 425613 881250 233556 500014 596532 621677 740170 305817 232077 709124 239371 431192 665814 808711 453414 629216 735026 698919 480996 233464 764169 514958 813918 714482 651240 923867 507027 811952 395118 141495 237965 580192 11932 365483 169673 870129 868096 239950 993864 …
Output: 4266

Example 3:

Input: 223 370425 51999 962698 744425 50071 633255 967347 388294 360970 176608 825364 368890 229703 662917 328775 756406 425731 540102 343566 552128 495830 999245 922200 943215 42597 833005 256449 144934 949697 263290 261272 522274 697560 803033 819935 366318 158970 557506 647892 159215 888597 607948 902726 271769 846833 688840 488455 587783 998618 948872 12326 111701 697707 573486 895760 322780 258977 337397 509110 600196 18586 206902 812429 631862 551263 191946 795280 938181 968727 894647 493913 885736 259231 255245 240690 436992 939904 964555 506479 705017 535674 295746 93397 114634 315163 626081 602382 579684 346931 74771 275893 806116 423166 301259 895206 335022 323598 786389 91964 160890 330484 180429 805871 711441 486726 124821 175003 923046 148420 617505 692322 15750 548525 884161 146279 …
Output: 1671

Constraints:

2 <= n <= 1373; 1 <= a[i],k <= 1000000.

Loading...
Test Cases:No test cases
No test cases available.
The ribbons Frugal Pairs Puzzle - MEDIUM Coding Problem | CodeTikki