CT42140

Nils's segments Reckoning

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Nils inherited the timber yard at the northern keep of Frostgate along with its curious bookkeeping system for segments. Time to make sense of it. 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 <= 2860; 0 <= a[i],k <= 1000000000.

Example 1:

Input: 2503 1808998013 110101560 338876013 97757196 860560441 489869625 210074089 851556680 238724257 956501717 140138591 338916516 941046342 255030109 304580732 123332533 655103574 465715481 928453190 486288080 865210298 85736460 335924672 718847764 992134965 305941694 764225639 40406854 539402827 334209376 658267568 335059208 381177538 729896115 23343211 272013589 81753182 83430713 231882013 337850583 716846214 164916601 729665976 28661981 92108428 690813028 35047858 358500319 642751383 105620861 215433664 756705054 436836031 388239336 88599033 227980557 791926784 485164049 246357603 165643670 525045233 876727010 962672478 328182350 313932402 887436495 568197089 755912952 912492645 434192747 959548992 269964484 262827900 747914998 196453758 610372334 726000475 275566325 227739576 959290243 9901…
Output: 3066351

Example 2:

Input: 1747 955781572 617399688 103572019 364197263 781083260 692872411 577970339 175685068 41287843 433685525 81736939 383467861 142652830 287434548 70146554 141236975 379115255 842337014 465086255 404543048 674006076 905386801 668117035 993125018 939303391 896353013 967535907 106886586 781219779 15988938 183524832 435985432 427086965 892043938 981997614 386169109 980131013 425777711 432737335 898574151 650507890 363141896 474684322 167536797 584105538 452024154 433844166 575939020 888195859 43879306 493347911 101313890 461469607 799131711 735785963 374966649 980718634 789755984 544235005 723593864 482853826 227284401 809056627 471140947 759281701 974522891 931967731 515336739 228131463 523314546 177304216 165281304 116759688 982841781 479238178 214179894 397595136 841846568 144685404 920626531 …
Output: 720487

Example 3:

Input: 1846 34209840 165219118 136080448 263979887 267910930 495995886 122750110 528038173 551529589 370227678 800430156 474375208 676496755 957438893 491196109 413697768 685452172 588362620 365320932 855408614 744974156 812094297 202137810 609454220 74489129 903210099 258796816 644229222 286939889 914740549 877262153 69802217 608794688 956190675 53151007 439655750 85801460 900432058 198022221 239664543 470149819 879433292 242968817 64791943 62449448 11723797 321360312 817498954 332724788 976904535 534417743 894320420 938896098 158054915 14354160 953450407 576318206 73856627 415618852 412309879 559693734 391309669 649152654 937835658 338420949 444568210 253729696 947901994 432533831 339729702 786525941 174130223 218291606 494380270 194430272 739054810 922770662 717065498 867439938 972819588 74136…
Output: 1036

Constraints:

2 <= n <= 2860; 0 <= a[i],k <= 1000000000.

Loading...
Test Cases:No test cases
No test cases available.
Nils's segments Reckoning - MEDIUM Coding Problem | CodeTikki