{"id":1185,"date":"2024-09-15T09:00:00","date_gmt":"2024-09-15T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=1185"},"modified":"2024-08-25T11:58:38","modified_gmt":"2024-08-25T03:58:38","slug":"zerojudge-d164","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-d164\/","title":{"rendered":"ZeroJudge D164: Best Choice"},"content":{"rendered":"\n\n\n<p>Z\u5148\u751f\u7684\u4e73\u725b\u5728\u74b0\u5f62\u570d\u5eca\u4e0a\u6392\u6210\u4e00\u5708\uff0c\u5c07\u6bcf\u982d\u725b\u8eab\u4e0a\u84cb\u4e0a\u4e00\u500b 0 \u5230 255 \u4e4b\u9593\u7684\u6574\u6578\uff0c\u8868\u793a\u9019\u982d\u725b\u7684\u300c\u54c1\u8cea\u6578\u300d\uff0c\u6578\u5b57\u8d8a\u5927\uff0c\u54c1\u8cea\u8d8a\u597d\u3002 Z\u5148\u751f\u70ba\u5c55\u73fe\u4ed6\u7684\u667a\u6167\uff0c\u5c0d\u8ce3\u4e3b\u5b9a\u4e0b\u4e00\u689d\u53e4\u602a\u7684\u7d04\u5b9a\uff1a\u8cb7\u4e3b\u53ea\u80fd\u5f9e\u570d\u5eca\u4e0a\u9023\u7e8c\u9078\u51fa\u4ed6\u6240\u9700\u7684 M \u982d\u4e73\u725b\u3002\u8eab\u70ba\u7cbe\u660e\u7684\u8cb7\u4e3b\uff0c\u4f60\u7576\u7136\u5e0c\u671b\u9078\u51fa\u7684\u9019\u96bb M \u982d\u4e73\u725b\u7684\u300c\u54c1\u8cea\u6578\u300d\u7e3d\u548c\u6700\u5927\u3002<\/p>\n\n\n\n<p>\u5982\uff1a\u6392\u6210\u4e00\u5708\u7684 5 \u982d\u4e73\u725b\u7684\u7bc4\u4f8b\uff1a10\u30013\u30019\u30017\u30011\u3002<\/p>\n\n\n\n<p>\u73fe\u5728\u4f60\u9700\u8981\u8cb7 2 \u982d\u4e73\u725b\u3002\u986f\u7136\u9078\u64c7\u6a19\u865f\u70ba 7 \u548c 9 \u7684\u5169\u982d\u4e73\u725b\u300c\u54c1\u8cea\u6578\u300d\u7e3d\u548c\u6700\u5927\uff0c\u70ba 16\uff0c\u662f\u4f60\u7684\u6700\u4f73\u7684\u9078\u64c7\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u7bc4\u4f8b\u6e2c\u8cc7<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7bc4\u4f8b\u8f38\u5165<\/th><th>\u7bc4\u4f8b\u8f38\u51fa<\/th><\/tr><\/thead><tbody><tr><td>EOF \u8f38\u5165\uff0c\u6bcf\u7d44\u6e2c\u8a66\u8cc7\u6599\u7684\u7b2c\u4e00\u884c\u662f\u5169\u500b\u6578 N (1 &lt;= N &lt;= 10000) \u548c M (1 &lt;= M &lt;= 5000)\uff0cN \u8868\u793a\u570d\u5eca\u4e2d\u4e73\u725b\u7684\u6578\u76ee\uff0c\u800c M \u8868\u793a\u4f60\u6253\u7b97\u8cfc\u8cb7\u7684\u4e73\u725b\u7684\u6578\u76ee\uff0c\u5169\u500b\u6578\u4e4b\u9593\u7528\u7a7a\u683c\u9694\u958b\u3002<br>\u63a5\u4e0b\u4f86\u7684 N \u884c\uff0c\u6bcf\u884c\u6709\u4e00\u500b 0 \u5230 255 \u7684\u6574\u6578\uff0c\u4ee5\u9806\u6642\u91dd\u6216\u9006\u6642\u91dd\u9806\u5e8f\u7d66\u51fa\u6bcf\u982d\u4e73\u725b\u7684\u300c\u54c1\u8cea\u6578\u300d\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u7b2c\u4e00\u982d\u4e73\u725b\u8207\u6700\u5f8c\u4e00\u982d\u4e73\u725b\u5728\u4f4d\u7f6e\u4e0a\u662f\u76f8\u9130\u7684\u3002<\/td><td>\u5c0d\u65bc\u6bcf\u500b\u8f38\u5165\uff0c\u8acb\u8f38\u51fa\u4e00\u884c\uff0c\u5373\u4f60\u9078\u51fa\u7684\u9023\u7e8c\u7684 M \u982d\u4e73\u725b\u7684\u6700\u5927\u300c\u54c1\u8cea\u6578\u300d\u7e3d\u548c\u3002<\/td><\/tr><tr><td>5 2<br>10<br>3<br>9<br>7<br>1<\/td><td>16<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p>\u5c07\u54c1\u8cea\u6578\u7684\u524d\u7db4\u548c\u7d00\u9304\u4e0b\u4f86\uff0c\u4e26\u4e14\u5f9e\u982d\u5230\u5c3e\u5224\u65b7\u76ee\u524d\u4f4d\u7f6e\u5230\u4e4b\u5f8c M \u500b\u5976\u725b\u7684\u54c1\u8cea\u6578\u7e3d\u548c\uff0c\u5982\u679c\u6709\u9047\u5230\u9700\u8981\u5c3e\u929c\u63a5\u982d\u7684\u60c5\u6cc1\uff0c\u5c31\u5148\u5c07\u76ee\u524d\u5df2\u7d93\u6709\u7684\u54c1\u8cea\u6578\u52a0\u8d77\u4f86\uff0c\u518d\u4f86\u628a\u5269\u4e0b\u7684\u5f9e\u7b2c\u4e00\u500b\u4f4d\u7f6e\u958b\u59cb\u52a0\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=d164\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge D164: \u6700\u4f73\u9078\u64c7<\/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;\n#include &lt;vector&gt;\nusing namespace std;\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    int N, M;\n    while (cin &gt;&gt; N &gt;&gt; M) {\n        vector&lt;int&gt;prefix;\n        prefix.push_back(0);\n        int ans = -999;\n        for (int i = 1; i&lt;=N; i++) {\n            int tmp;\n            cin &gt;&gt; tmp;\n            prefix.push_back(prefix[i-1]+tmp);\n        }\n        for (int i = 1; i&lt;=N; i++) {\n            if (i + M - 1 &lt;= N) {\n                const int calc = prefix[i+M-1] - prefix[i-1];\n                ans = max(ans, calc);\n            }\n            else {\n                int calc = prefix[N] - prefix[i-1];\n                const int left = M - (N-i+1);\n                calc += prefix[left] - prefix[0];\n                ans = max(ans, calc);\n            }\n        }\n        cout &lt;&lt; ans &lt;&lt; &quot;\\n&quot;;\n    }\n}\n\n\/\/ZeroJudge D164\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Z\u5148\u751f\u7684\u4e73\u725b\u5728\u74b0\u5f62\u570d\u5eca\u4e0a\u6392\u6210\u4e00\u5708\uff0c\u5c07\u6bcf\u982d\u725b\u8eab\u4e0a\u84cb\u4e0a\u4e00\u500b 0 \u5230 255 \u4e4b\u9593\u7684\u6574\u6578\uff0c\u8868\u793a\u9019\u982d\u725b\u7684\u300c\u54c1\u8cea\u6578\u300d\uff0c\u6578 [&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":[25],"tags":[20,8,13,9],"class_list":["post-1185","post","type-post","status-publish","format-standard","hentry","category-ioi-apcs","tag-20","tag-8","tag-13","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1185","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=1185"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1185\/revisions"}],"predecessor-version":[{"id":1187,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1185\/revisions\/1187"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=1185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=1185"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=1185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}