{"id":1195,"date":"2024-09-28T09:00:00","date_gmt":"2024-09-28T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=1195"},"modified":"2024-08-31T02:29:31","modified_gmt":"2024-08-30T18:29:31","slug":"zerojudge-f934","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-f934\/","title":{"rendered":"ZeroJudge F934: The Lost 20 Years"},"content":{"rendered":"<p class=\"translation-block\">Stock King Xiao Fang has recently faced a series of losses, with every stock he buys going down. He has lost almost 20 years\u2019 worth of savings, leading people to say: \u201cThe Lost 20 Years.\u201d<\/p>\n\n\n\n<p class=\"translation-block\">Now, **Xiao Fang** has just enough money to buy one more stock and has decided to invest in **0612 CIA**.<\/p>\n\n\n\n<p class=\"translation-block\">As a member of 0612 CIA, you have discovered confidential information about future stock prices. With this valuable knowledge, you decide to help Xiao Fang by advising them on the best times to buy and sell the stock, and how much profit they can make.<\/p>\n\n\n\n<p class=\"translation-block\">However, to pique **Xiao Fang's** interest in the information you\u2019ve calculated, you only need to determine how much money can be made.<\/p>\n\n\n\n<p class=\"translation-block\">\u26a0\ufe0f Note that you can only **buy and sell once**!<\/p>\n\n\n\n<p>\u26a0\ufe0f Note that you can only sell after buying!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Sample Inputs\/Outputs<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Sample Input(s)<\/th><th>Sample Output(s)<\/th><\/tr><\/thead><tbody><tr><td class=\"translation-block\">The input consists of a single line with many numbers, representing the future daily closing prices of the stock. All numbers are guaranteed to be positive integers, and the first number must be 100.<\/td><td class=\"translation-block\">Output a single number that represents the maximum profit for the stock expert, Xiaofang.<\/td><\/tr><tr><td>100 108 115 115 120 109 110<\/td><td>20<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Thought Process<\/h2>\n\n\n\n<p>Use EOF to read the data, and declare two variables: min, initialized to 100, and ans, initialized to 0.<\/p>\n\n\n\n<p>When the received data is greater than min, check if the current ans is less than the received data minus min. If it is, update ans to be the received data minus min. If the received data is less than min, update min to the received data.<\/p>\n\n\n\n<p>Lastly, output ans.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Sample Code\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=f934\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge F934: The Lost 20 Years<\/a><\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-cpp\" data-lang=\"C++\"><code>#include &lt;iostream&gt;\nusing namespace std;\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    int N, min = 100, ans = 0;\n    while (cin &gt;&gt; N) {\n        if (N &gt; min) {\n            ans = max(ans, N-min);\n        }\n        if (N &lt; min) min = N;\n    }\n    cout &lt;&lt; ans &lt;&lt; &quot;\\n&quot;;\n}\n\n\/\/ZeroJudge F934\n\/\/Dr. SeanXD<\/code><\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>\u80a1\u738b&nbsp;\u5c0f\u65b9&nbsp;\u6700\u8fd1\u80a1\u7968\u8cb7\u54ea\u4e00\u5f35\u54ea\u4e00\u5f35\u5c31\u8dcc\uff0c\u628a\u904e\u53bb\u5c07\u8fd1 20 \u5e74\u7684\u58d3\u6b72\u9322\u90fd\u8f38\u5149\uff0c\u6240\u4ee5\u5927\u5bb6\u90fd\u8aaa\uff1a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","footnotes":""},"categories":[6],"tags":[8,13],"class_list":["post-1195","post","type-post","status-publish","format-standard","hentry","category-6","tag-8","tag-13"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1195","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/comments?post=1195"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1195\/revisions"}],"predecessor-version":[{"id":1197,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1195\/revisions\/1197"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=1195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=1195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=1195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}