CT34476

The Frugal Pairs Beneath Grapehollow

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

It is audit day at the terraced vines of Grapehollow. Harish spreads the segments records across the table and picks up a sharp pencil. 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 <= 2440; 0 <= a[i],k <= 1000000.

Example 1:

Input: 12 1194957 296673 689025 438155 575693 77831 231013 506038 272500 486924 602797 276811 101787
Output: 63

Example 2:

Input: 715 1934302 923052 759728 355358 828962 973852 649893 310248 69824 426139 151606 588554 677909 832507 60710 682617 204339 766335 943671 259333 653027 945487 672679 341270 389212 281801 669647 941945 923235 48759 721513 148346 896789 515880 377701 703671 788236 201684 468155 547290 248685 790219 6130 127149 580793 909399 666453 461073 730081 121337 690031 407226 484995 560204 788717 884301 201917 291110 357333 461540 923923 430967 852264 942637 992251 804987 764422 256253 849504 880731 437755 751366 297835 969115 477618 190552 65731 583317 211150 766500 192553 991032 996048 349809 208154 128583 641463 37385 898735 285923 692926 494889 328952 842012 981961 342017 121198 398410 427928 697749 688589 18280 514825 872029 807103 228562 548865 492923 291999 823084 424451 720539 703976 756920 31246…
Output: 254618

Example 3:

Input: 1637 1459786 454549 214004 977800 311441 616681 301027 358306 304542 336696 274261 213646 600871 15444 685306 259304 711474 924728 201840 462831 249620 810289 796182 765436 362942 553270 544332 203595 729607 78519 583916 420274 392526 173598 547631 134888 309086 465183 311057 375382 543994 601218 919089 397250 456287 15181 930632 148151 367331 829142 11348 125732 479277 918650 423470 93322 444608 965773 305437 471557 545662 864030 31853 586402 960459 494846 42796 649588 462793 683948 685702 777850 672300 91316 151206 460224 944346 733538 438761 165689 531382 803745 38973 239305 237295 397023 328386 340886 595385 748922 993502 964940 911872 388626 308885 506897 632992 394591 220092 6036 259676 492695 433183 307423 199393 792469 307283 399323 702840 830452 687734 76688 297129 84959 312968 33…
Output: 1149588

Constraints:

2 <= n <= 2440; 0 <= a[i],k <= 1000000.

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