CT29032

The Single Trade at Padmore

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Before the gates of the lily shoals of Padmore close for winter, Theo must finish the queues ledger - one figure at a time. Task: Prices over n days; buy once and sell once later. Print the maximum profit (0 if none). Input format: First line: n. Second line: n prices. Output format: Print the maximum profit. Constraints: 1 <= n <= 4000; 0 <= price <= 10^9.

Example 1:

Input: 1176 257954694 818871360 632749917 178481475 500385463 468923050 742689790 338928779 244351320 332020481 930123632 729781858 762893718 886338764 755302247 149137435 719595695 782788044 275642600 597604686 103070610 189864353 439090057 992390794 281532508 147177751 488360990 447414310 429847550 982655138 910736523 510199503 207815822 676809412 401027529 815247592 388952997 771990104 732659322 406714632 751923175 356555800 330892286 661799614 947534717 128446998 880960620 333382970 915604284 869905708 38852154 552018020 985364670 982068272 857503677 757250010 463007456 897808861 138227698 801102234 173226479 841825878 971208618 66342394 511603826 243403925 885496242 423629399 468581463 62349781 639869598 503974602 17858173 407611951 705867308 292630265 381186936 510959284 600157925 215609816…
Output: 999959506

Example 2:

Input: 1090 283566370 266708859 941800441 595416849 770680024 939213913 427793572 308916370 520068244 632099563 351341525 631448153 802167233 791048553 878871279 481685265 893077206 583795694 959330213 172481122 643929077 368158421 642907166 866149491 755155628 823984238 435229225 524016506 244677200 745219614 988885567 480113703 914177409 852712555 452165197 671728741 225027405 417238698 640874380 462847937 293224468 663411197 494151167 169136873 683764296 723622093 269848721 573111471 256519711 703745332 566149830 382523989 589424612 117334429 892538885 501465904 338514269 552222663 342267804 408704174 396248305 373478979 293899179 407707215 682276743 658844019 603635264 959870194 10900163 334018084 625942513 824245638 655735700 290972426 291180337 152496649 692607723 525880342 794626259 696905…
Output: 997176814

Example 3:

Input: 2392 932124175 693448457 32906757 707230228 852539946 61715452 184752819 790944247 166917704 856287361 991631507 937530811 275906014 950039507 569406539 568690898 810013077 627823730 402263097 359351841 212801073 175665749 504673789 738255545 947288200 659674410 324055175 46734592 88072053 242638546 27808754 50222842 193524635 948356548 552378607 845873766 957180275 504662733 427746130 776636262 963838770 209550194 300519575 787732297 306624786 588991235 801431496 548122409 272725931 115554655 424335273 962650962 162741167 463627701 253036172 894640989 855018386 903253832 330491330 955294043 105615971 649787868 981935381 314116198 203364246 873418462 993871041 829023195 285818022 569980259 779643964 486170108 331401707 996602442 550720875 995411250 328999095 429179733 318938483 903229209 6…
Output: 998774144

Constraints:

1 <= n <= 4000; 0 <= price <= 10^9.

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