CT51742

Herald's vials Reckoning

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Herald the tallyman watches over the spice bazaar of Saffronia's stores of vials. A careful computation stands between order and chaos. 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 <= 3924; -1000000000 <= a[i],k <= 1000000000.

Example 1:

Input: 1038 935259011 704933326 181752505 -259735762 824658795 -9039781 232846232 831769996 -41000048 739891738 462434541 256727044 -346609127 -917640218 -942711944 -864752247 622999535 -973761732 -490631560 -427490633 -739699603 762379549 -445108186 544097846 -352486056 -626773172 -554413974 -765841731 -939849437 361445923 793092469 750569301 142838030 -863303448 -815137242 39597806 -85151804 -429460264 -306574552 -900235882 -215836441 387006181 -957718741 169346628 329906245 -544711230 101329417 72228796 596230741 433858943 174986253 432036412 297846869 320621442 -753523450 546659055 727886229 -222798172 428667079 -426759470 968470413 -182255000 -138656493 771626880 -147530445 695336533 -578291277 697013075 154277906 554843566 -428704777 -408613971 344605107 -302889834 661783310 -716965364 -103…
Output: 935259883

Example 2:

Input: 809 1529503031 -399245004 -993112171 -323365163 -369752983 509541471 -522848344 -148549132 -137272736 458996789 210085548 181936202 -316440970 925560372 470182031 -731927994 802326302 -72918918 199565925 -485850607 708898909 375353377 -990397743 -981100428 627467076 654958317 -742113607 264907095 -97952391 -651961672 -81456529 340562603 -567285830 723590861 998731799 778239565 -706449456 735218720 -454486056 -7067571 -598398642 -505915683 510527611 176474046 959773615 146264052 -357327527 619876629 875492738 -191787861 -273377205 681889 754897881 -422128445 101321840 -877443845 -477191409 853322384 998358328 -403166091 -941481696 -92610825 931589081 -512743465 19060013 -584201831 404265868 -551043783 588650485 939082753 440291946 299041282 -119210858 -785392979 -316221487 -222179163 546996…
Output: 1529510327

Example 3:

Input: 2652 1778428269 22190594 650979931 266575661 -45392422 223992234 -591171840 -108428246 447592923 52017733 -249775931 -78097246 -204392467 914128856 -810092898 -595266364 120252321 -839397945 828977920 398402793 24490502 320364836 551600320 -849638532 -729238783 -839786456 308718715 -138152318 -114926305 -926879857 -139188696 -700272521 854541333 -909152931 -520574963 775283400 -909304307 -936528334 -815420822 503074706 709758407 525650577 513672692 -795453956 -704530462 101100827 280797336 -705194768 -789023498 -887572257 861172669 44570717 -484175932 342718144 424154864 -777465193 519184510 -763625667 779976838 -698138766 -312030871 -947612772 -767525370 909494757 237370362 -228865058 752624456 -671651002 -254879573 386033285 -55441083 71198920 -939228776 -821975022 161516327 -721369571 -…
Output: 1778427282

Constraints:

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

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