CT22349

Surveyor and the Runner-Up

EasyL3 · Syntax SurferAcceptance: 0.0%XP: 20

The harbor bell rings at the windmill fields of Gusthaven; Surveyor weighs the day's ingots manifests and starts the calculations. 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 <= 504; -1000000 <= a[i] <= 1000000; answers fit a signed 64-bit integer.

Example 1:

Input: 196 652713 -861162 888442 34749 520426 -833407 911200 872301 -931193 574677 -961499 617353 377422 -88501 83020 -807478 -455255 500012 440916 -961451 -287024 44267 -782178 -298043 657629 -959713 -794357 -481843 -28292 802301 -824577 -119108 613544 22524 -760739 -112259 514942 914564 662658 -307006 -604940 119731 929797 -890761 2908 924649 196726 435967 -361450 -610232 490245 -126607 -669055 353883 612259 -243096 773192 957113 666233 244420 -405337 128835 -573127 126643 -396169 628795 121557 -832021 -83945 331198 691161 -728251 934258 437606 786938 -916745 19168 -59408 315632 964978 818943 -144624 183219 -974329 -378421 118515 -986578 4339 -372578 514253 924359 978233 -266708 131029 412998 767748 -468777 476537 50227 372073 373151 216533 -28689 69388 263355 -306251 616362 -238788 -523858 769…
Output: 964978

Example 2:

Input: 189 -288477 894101 -331713 -194627 -258497 -966903 -872834 -101766 522574 -552761 -820833 417266 64980 -670474 659485 84113 -549597 511232 646779 -650005 -652760 -289709 463055 61005 80022 -617147 538478 -977249 -927503 -518423 -327285 313622 945183 -16361 61677 -156228 309740 694939 594240 564586 211330 -920525 -352679 642238 268490 610644 -666214 144143 897059 971214 -434566 -738092 753261 139505 82194 174971 -61816 -695146 -102974 112492 -199405 -729281 432605 -37874 -508257 388117 229528 -378873 615799 519430 494775 -472451 621432 132204 -440446 704675 -372303 -8608 -915679 264681 -321088 569736 -68402 -447001 841760 -385733 -279587 -847067 -668350 834957 -466391 -23800 -548806 982605 316245 841171 -673180 887121 211126 373721 863643 -110782 -265869 279941 51283 -807831 4112 711896 -63…
Output: 982605

Example 3:

Input: 178 801638 -404224 -440955 -407450 -751653 -736795 -752892 631442 55793 487950 517357 -207109 691112 523757 68312 145785 -79575 697358 -718976 -339450 105267 545054 -628820 -938588 -907573 -791188 -11303 341228 -918499 -297230 632351 815928 -523917 -822876 99813 -825046 -644548 -540295 -599947 857763 -423546 813101 -543772 -322425 -893682 129426 248036 54683 -514776 -6997 -709573 -928269 95316 -642844 -521053 -995607 16041 -807501 394530 846766 776303 334171 -176025 -312354 272860 543650 -965614 666396 -234287 -475892 -708253 119529 -935073 -277831 240805 -846530 290220 957041 -630356 838152 -438508 -834292 -806031 -489363 381225 859290 -779724 -521484 357511 -916575 991026 -295241 819278 529329 811030 676018 -146340 124772 -330844 -990751 929408 64424 -590225 33129 222677 -224148 -994645 …
Output: 991026

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.