CT32016

Last segments of Ravi

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

It is audit day at the moonlit lagoon of Selene. Ravi 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 <= 2747; 0 <= a[i],k <= 1000000.

Example 1:

Input: 700 1208007 786826 62240 452564 629657 15115 29637 448324 311743 114504 588555 194972 93927 496125 703524 860421 932599 809076 195019 877052 775832 484460 984398 205294 372327 178768 612742 385132 442073 395487 209202 99122 693267 507382 50143 907927 722603 941773 83228 823791 654580 542605 730044 193786 781466 86112 59083 835078 243104 165897 803674 247651 666076 996071 180818 967480 630980 480654 807461 328110 661376 529932 418086 827387 73034 319675 415935 644942 748255 750076 616864 323884 778112 123413 580544 748587 987726 957035 243228 226230 142419 625613 751797 239369 411126 183688 431604 730023 816972 619679 997320 709258 927371 273008 817103 298459 21230 267348 589411 237471 961472 407644 305734 831302 438553 724780 887640 404063 129521 546007 190208 352759 31572 634809 116588 78…
Output: 161932

Example 2:

Input: 2058 471594 95996 178473 424049 983547 213076 145332 455316 925112 984850 903745 833068 129806 349613 339484 944598 926803 73503 332656 600236 572777 554326 901923 521270 44535 476212 285006 135471 573281 265152 401167 110159 804682 856852 125108 232091 743485 849215 884440 375399 397303 488249 321670 598607 832977 512865 299525 706331 331351 76009 987779 778528 874580 423159 7836 140122 563216 279746 36369 818925 240889 74193 415659 644649 934776 570856 695981 797040 663183 619659 644131 481271 464278 179270 457062 713689 828885 973915 625272 922945 102922 202350 854529 107168 495042 764771 315790 894933 732898 178905 410326 989647 94311 806251 998051 221916 699616 168458 419771 419652 59462 193751 856559 751737 879257 378810 550409 563870 629068 244822 312724 62670 301338 828012 606187 4…
Output: 243227

Example 3:

Input: 1867 1639052 981574 99286 208435 200054 909708 888185 384396 21870 897703 409414 450284 478132 406513 761892 995424 950306 167566 117178 424909 558042 429554 424240 845393 944469 156752 210154 188815 610288 955605 168367 731403 854812 983716 641455 332985 449617 405337 268979 437900 925849 123833 633613 690577 132827 74120 396467 176611 20795 867813 366916 178022 352715 335703 490819 48348 842922 625832 31620 120508 518916 505176 868956 820689 782238 898640 715951 43465 95927 107462 994275 424744 973354 32550 359744 948248 207695 919796 421326 937828 564401 461247 342216 252034 930113 434458 610137 276827 718744 295962 686062 129567 369465 8468 266010 302773 427128 931644 32979 453753 675884 30098 994323 873479 656700 740658 61623 810539 413706 788167 121122 643596 55309 687611 125241 8120…
Output: 1624314

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Last segments of Ravi - MEDIUM Coding Problem | CodeTikki