CT53228

The registers at Serpentis

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the jade shrine of Serpentis, someone must prove the quality of the harvest. This year the task falls to Botanist, armed only with the registers register. Task: Among all pairs of distinct elements, print the pair sum that is closest to k. If several tie, print the smaller sum. Input format: First line: n and k. Second line: n integers. Output format: Print the closest achievable pair sum. Constraints: 2 <= n <= 1107; -1000000000 <= a[i],k <= 1000.

Example 1:

Input: 1042 -736611038 -236999040 -422771797 -123391007 -859191777 -408615609 -969508009 -414429790 -884147753 -803683255 -777150773 -590837576 -915596626 -131254146 -731983102 -715965000 -607861114 -87762225 -824581028 -584719647 -547505111 -402181672 -670706100 -814727095 -237327669 -997454472 -28789892 -355786680 -314384191 -215716945 -431711951 -585588116 -986110833 -195461936 -198855470 -130565347 -236645432 -337420082 -551512542 -960350140 -25740373 -479758613 -850969454 -938997174 -904660310 -485680955 -755738638 -615982118 -239655221 -754820396 -716863444 -740656188 -474817563 -172074411 -79396199 -611840912 -176434827 -383027275 -6508157 -858772976 -22761618 -849225110 -983938988 -682839012 -309253151 -646502908 -913870723 -729979404 -8316732 -523335109 -225146800 -342106303 -145292572 -…
Output: -736611571

Example 2:

Input: 943 -853074551 -680343064 -25407444 -222879225 -656920752 -423413940 -91739396 -110614985 -985468249 -83592126 -348349558 -293266237 -94662574 -311075997 -280054683 -906971828 -269600996 -687366626 -130528084 -258035496 -250761003 -770706903 -191158568 -941191975 -286645891 -984637402 -547194440 -888464468 -516480665 -689452528 -514772619 -835061614 -754928804 -548485733 -426315027 -305960504 -163277266 -515817180 -941933924 -561609758 -651602414 -247895914 -343248511 -373033953 -921882672 -754821129 -528286516 -350630550 -387696704 -574315731 -180955399 -891869551 -105787711 -84747895 -879804688 -811909454 -390523227 -917797523 -126847839 -817785991 -911757534 -203994957 -912766207 -789153267 -787015766 -237217784 -460352583 -921724984 -671651178 -971287018 -503258901 -593747422 -23909031…
Output: -853071201

Example 3:

Input: 643 -901430971 -42098199 -964387564 -282465222 -944018715 -972239538 -81409592 -532193325 -360336611 -485862286 -201560138 -831944581 -166420707 -299660429 -608638155 -579918125 -245488020 -319054061 -777313950 -328156161 -330821448 -247690746 -624547736 -946217330 -966333131 -476271130 -252988386 -188403308 -35381558 -624080655 -287044957 -232114493 -266373714 -842984347 -105389834 -868139485 -490649459 -207316234 -198264233 -612341050 -719413380 -744784783 -267424871 -563281088 -919149478 -240377976 -48921691 -805701805 -398172895 -500354713 -504236591 -357558880 -19003834 -475707010 -971524893 -593143786 -17541766 -120008408 -370542640 -188688741 -399994960 -100582651 -986867342 -647665494 -430406393 -107548099 -829267570 -967760719 -155767423 -452838100 -946805546 -583464750 -706759654…
Output: -901428712

Constraints:

2 <= n <= 1107; -1000000000 <= a[i],k <= 1000.

Loading...
Test Cases:No test cases
No test cases available.
The registers at Serpentis - MEDIUM Coding Problem | CodeTikki