CT23723

The Runner-Up of the Gleaming barrels

EasyL3 · Syntax SurferAcceptance: 0.0%XP: 20

At the salt flats of Palemere, Chetan records each barrels in a worn leather ledger. The guild wants answers, not guesses. Task: Read n integers and print the second distinct largest value. If every value is the same, print -1. Input format: First line: n. Second line: n space-separated integers. Output format: Print the second distinct maximum, or -1 if none. Constraints: 1 <= n <= 485; 0 <= a[i] <= 1000000; answers fit a signed 64-bit integer.

Example 1:

Input: 256 250374 294945 396717 495484 619240 215457 95203 617097 430072 260368 218564 91173 532706 464454 83043 806283 558424 51899 497670 773699 68729 621830 196427 902241 17007 909733 307128 751151 293682 782289 1159 950354 960758 899564 140159 125771 190803 825648 351263 485479 596078 594445 399304 176224 915203 664852 114534 22929 992476 235572 195164 514492 999774 144459 218828 763978 602515 358897 349205 151011 43743 959001 943104 16221 440326 913371 600400 254 261712 933092 628130 41687 332600 692641 721142 2453 59675 783433 856359 198368 976459 246145 655762 341078 679285 893222 79587 412632 84059 996956 107506 404901 264042 494352 568872 732420 270028 911730 320438 295577 683201 175155 510688 895393 150532 686977 243000 847640 412514 977511 317369 458888 869784 434497 932530 879092 5100…
Output: 996956

Example 2:

Input: 271 22991 57105 750784 574907 817267 163668 488316 20896 487284 167104 803831 712157 319149 671646 489418 367483 34280 531773 292248 152019 221706 659150 667682 735818 96371 429468 127308 969837 455539 122440 929805 791711 632131 130637 181734 258738 212965 241715 622036 265668 776517 442896 942074 538059 523051 517708 928492 373907 715860 227769 133937 103607 552069 927706 416382 35726 501501 115973 58724 934412 752613 157349 616444 94906 886566 132434 206691 393069 230621 836256 212872 261375 471447 893444 16008 440348 571561 788687 14994 84868 281083 409838 905563 533415 152865 822077 268598 171170 651989 570126 277600 835004 325729 527456 311970 153433 48724 136603 702258 892485 584956 245767 36227 407778 204330 25163 801160 211227 688711 929734 681564 720907 151865 470559 672267 27813…
Output: 979004

Example 3:

Input: 414 634598 865822 255494 723252 557471 759742 975486 805825 681170 732873 39581 268369 210096 94746 843175 12269 793493 53306 523002 53340 327523 119851 855343 800272 76821 513083 30482 851677 960922 822389 413706 81626 972152 676193 510239 65966 185023 397206 828528 704879 929750 190370 426288 747497 420496 322464 866507 647576 619575 951663 698191 962468 602904 486159 714951 962058 485008 540975 169859 235620 647452 823919 921 831450 452190 591950 606684 638499 955520 398083 196222 780405 82175 810123 190786 905986 805969 290421 671433 879831 509419 305580 536846 767339 175577 765911 525633 625659 314451 8351 796750 640617 844009 529509 698338 426057 559366 451821 896768 85833 582096 787158 744146 92242 852861 500558 589370 800187 91646 945183 540461 400362 415448 700741 137514 751759 34…
Output: 995317

Constraints:

1 <= n <= 485; 0 <= a[i] <= 1000000; answers fit a signed 64-bit integer.

Loading...
Test Cases:No test cases
No test cases available.
The Runner-Up of the Gleaming barrels - EASY Coding Problem | CodeTikki