CT23430

Jace and the Runner-Up

EasyL3 · Syntax SurferAcceptance: 0.0%XP: 20

Every season at the crystal caves of Luminar, someone must schedule the next expedition. This year the task falls to Jace, armed only with the readings register. 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 <= 408; 0 <= a[i] <= 1000000; answers fit a signed 64-bit integer.

Example 1:

Input: 217 607447 195720 6384 170459 346186 203515 262138 777936 913745 547194 634944 197659 591423 162321 798942 154911 486183 577542 547116 12578 144322 62323 835051 463892 48110 691812 912214 383407 555165 648068 899192 27977 264003 235335 508353 736132 74824 316816 839873 543133 264493 388570 147257 70017 26875 972557 569184 539124 245026 613491 918440 920062 745093 344243 969554 598248 143573 675622 809700 254743 737901 184583 956681 182123 941992 553010 956539 177979 60482 432415 340888 686959 319047 327306 286126 186569 205813 586864 216019 657434 369092 779749 179367 658993 158407 3931 809025 872980 353793 881063 857097 844825 588909 394709 561030 453388 848014 156028 666436 804781 718702 358900 154650 637185 56613 435794 196179 521970 958016 491479 5849 281889 351927 523480 603946 791991 654063 628519 343208 145039 91430 321807 890828 551368 953139 133450 605352 666141 369100 397958 654236 390842 41683 386254 970201 567421 376061 627627 473177 880420 713090 273884 691013 389649 381915 242893 296138 386773 947348 308024 691525 660800 463916 391177 626837 199975 449856 967132 833005 602898 409319 907118 770498 955730 291658 586409 238296 184803 985942 819086 449189 94091 699350 529158 247174 387861 432803 796011 432921 514128 322265 440179 308976 306218 200315 929163 206922 200340 133631 357539 398027 39285 606966 551704 506167 208111 506308 296032 281182 944630 848723 199364 618057 937788 551886 569209 518194 180778 674846 380250 632079 837436 802868 184509 869414 277828 507320
Output: 972557

Example 2:

Input: 121 754565 949135 174499 693320 646009 283296 573891 13443 852418 83713 880836 856842 697657 566939 701456 38015 470564 152964 18718 137388 802027 861092 58517 213127 687317 996662 600652 622373 274132 962077 605122 242510 576064 539709 607768 810820 579856 650472 769567 41355 64360 387565 76712 424261 736403 279704 657102 202453 993632 727871 916472 477589 350276 221251 285173 199431 876758 900614 314190 215962 249493 101793 906346 255825 570460 609035 897989 581149 908373 353036 288237 23953 44732 691871 627408 229283 159218 905310 931312 366760 621107 492563 452667 580613 50947 533801 930016 157030 9051 383891 440964 456557 852933 320448 196219 848521 976898 605077 804627 943986 752453 80440 365582 955343 206489 113733 993309 444722 557747 546287 148039 157438 615173 858765 940309 315115 563865 374562 192187 941962 973926
Output: 993632

Example 3:

Input: 124 917929 266556 833367 876047 808582 115873 305052 370034 502792 975194 400125 299100 716651 874258 75162 474681 901723 10406 383660 462004 998169 432261 174759 959898 195884 13848 816139 820704 465080 793158 84124 665168 631683 285206 488588 378228 705750 56144 637092 221289 6843 627751 190954 332693 233548 491316 354088 259263 559558 406935 187905 350071 691712 481687 501149 268214 53946 526881 767271 273033 492095 677777 206547 940899 271823 275109 657970 995301 385544 303116 772274 170615 846986 591840 614863 755832 416513 920362 288219 180773 84246 394985 910534 452883 795201 465920 29709 983643 943185 665548 790390 400205 438315 810805 646402 518638 992757 258576 628769 849606 852284 990353 608953 588318 632703 40610 154867 586143 927121 206328 900067 860298 789953 857160 511829 455812 51128 665840 591284 279493 481076 411284 339077 700278
Output: 995301

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Jace and the Runner-Up - EASY Coding Problem | CodeTikki