{"id":333,"date":"2024-04-27T23:55:55","date_gmt":"2024-04-27T15:55:55","guid":{"rendered":"https:\/\/seanxd.com\/?p=333"},"modified":"2024-04-27T23:55:57","modified_gmt":"2024-04-27T15:55:57","slug":"zerojudge-f174","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-f174\/","title":{"rendered":"ZeroJudge F174: Slicing Cake"},"content":{"rendered":"\n\n\n<p class=\"\">\u5c0f\u660e\u904e\u751f\u65e5\uff0c\u5bb6\u4eba\u70ba\u4ed6\u6e96\u5099\u4e00\u500b\u9577\u65b9\u578b\u7684\u6c34\u679c\u86cb\u7cd5\uff0c\u7531\u65bc\u4ed6\u662f\u58fd\u661f\uff0c\u4ed6\u53ef\u4ee5\u5148\u5207\u86cb\u7cd5\u53bb\u5403\u3002\u9019\u500b\u86cb\u7cd5\u5206\u6210 N \u5c0f\u584a\uff0c\u6bcf\u584a\u90fd\u6709\u4e00\u7a2e\u9921\u6599\u3002<br>\u5c0f\u660e\u5c0d\u6bcf\u7a2e\u9921\u6599\u6709\u4e0d\u540c\u7684\u559c\u597d\u5ea6\uff0c\u559c\u597d\u5ea6\u6578\u503c\u82e5\u70ba\u6b63\u503c\u4ee3\u8868\u559c\u6b61\uff0c\u8ca0\u503c\u4ee3\u8868\u53ad\u60e1\uff0c\u96f6\u503c\u70ba\u6c92\u6709\u611f\u89ba\u3002 \u70ba\u4e86\u7701\u6642\u9593\uff0c\u5c0f\u660e\u53ea\u6311\u9023\u7e8c\u4e00\u6bb5\u86cb\u7cd5\u4f86\u5403\uff0c<br>\u9019\u6a23\u5c31<strong>\u53ea\u8981\u5207\u4e00\u5200\u6216\u5169\u5200<\/strong>\u3002\u800c\u4e14\uff0c\u70ba\u4e86\u8b93\u5176\u5b83\u4eba\u4e5f\u80fd\u5403\u5230\u86cb\u7cd5\uff0c\u4ed6<strong>\u300c\u81f3\u591a\u300d\u53ea\u6703\u6311 K\u5c0f\u584a<\/strong>\u7684\u4efd\u91cf\u5403\uff0c\uff08\u53ef\u4ee5\u4e0d\u62ff\u6eff K\u5c0f\u584a\u5206\u91cf\u7684\u86cb\u7cd5\uff0c\u751a\u81f3\u662f\u4e0d\u62ff\uff09\u3002<br>\u8209\u4f8b\u800c\u8a00\uff1a\u5047\u5982 N = 7\u3001K = 3\uff0c\u6bcf\u5c0f\u584a\u86cb\u7cd5\u5c0f\u660e \u7d66\u7684\u559c\u597d\u5ea6\u8a55\u5206\u5982\u4e0b\uff1a 3 7 -1 9 2 2 1<br>\u62ff\u5230 [7, -1, 9] \u9019\u4e09\u584a\u86cb\u7cd5\u7684\u7e3d\u5206\u6700\u9ad8\uff0c\u70ba 15 \u5206\uff0c\u7e31\u4f7f\u4e2d\u9593\u7684\u4ed6\u4e0d\u559c\u6b61\u5403 \u4e5f\u6c92\u95dc\u4fc2\u3002\u96d6\u7136 [9, 2, 2] \u9019\u6bb5\u86cb\u7cd5\u4ed6\u5168\u90e8\u90fd\u559c\u6b61\uff0c\u4e0d\u904e\u7e3d\u5206\u53ea\u6709 13 \u5206\u3002<br>\u8acb\u4f60\u5beb\u4e00\u500b\u7a0b\u5f0f\u8a08\u7b97\u51fa\u5c0f\u660e\u80fd\u5403\u5230\u7684\u86cb\u7cd5\u6700\u9ad8\u7e3d\u5206\u70ba\u591a\u5c11\u5206\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 nfd-wb-animate nfd-wb-fade-in-bottom-short\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7bc4\u4f8b\u8f38\u5165<\/th><th>\u7bc4\u4f8b\u8f38\u51fa<\/th><\/tr><\/thead><tbody><tr><td>\u7b2c\u4e00\u884c\u6709\u5169\u500b\u6b63\u6574\u6578 N (1 &lt;= N &lt;= 10<sup>5<\/sup>) \u548c K (1 &lt;= K &lt;= N)\uff0c<br>\u5206\u5225\u8868\u793a\u9577\u65b9\u5f62\u86cb\u7cd5\u6709 N \u5c0f\u584a\uff0c\u5c0f\u660e\u81f3\u591a\u53ef\u4ee5\u62ff\u8d70\u76f8\u7576\u65bc K \u5c0f\u584a\u7684\u9023\u7e8c\u5340\u6bb5\u86cb\u7cd5\u3002<br>\u63a5\u4e0b\u4f86\u4e00\u884c\u6709 N \u500b\u6574\u6578\uff0c\u4f9d\u5e8f\u4ee3\u8868\u7531\u5de6\u81f3\u53f3\u6bcf\u4e00\u5c0f\u584a\u86cb\u7cd5\u7684\u8a55\u5206<br>S<sub>i<\/sub> (|S<sub>i<\/sub>| &lt;= 100)\uff0c\u5169\u500b\u6574\u6578\u4ee5\u4e00\u500b \u7a7a\u767d\u9694\u958b\u3002<\/td><td>\u8acb\u8f38\u51fa\u4e00\u884c\u6574\u6578\uff0c\u8868\u793a\u5c0f\u660e\u80fd\u5403\u5230\u7684\u86cb\u7cd5\u7684\u6700\u9ad8\u5206\uff0c<strong>\u5982\u679c\u5b8c\u5168\u4e0d\u62ff\uff0c\u8f38\u51fa 0<\/strong>\u3002<\/td><\/tr><tr><td>7  3<br>3  7  -1  9  2  2  1<\/td><td>15<\/td><\/tr><tr><td>5  4<br>-3  -4  -5  -6  -7<\/td><td>0<\/td><\/tr><tr><td>10  4<br>1  -5  7  2  5  -2  6  3  0  2<\/td><td>14<\/td><\/tr><tr><td>10  5<br>10  -3  -5  9  -5  -6  10  7  -20  16<\/td><td>17<\/td><\/tr><tr><td>10  5<br>10  -3  -5  9  -5  -6  10  7  -20  18<\/td><td>18<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">ZeroJudge F174 \u7bc4\u4f8b\u6e2c\u8cc7<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p class=\"\">\u5c07<strong>\u524d\u7db4\u548c\u5b58\u5230\u9663\u5217\u4e2d<\/strong>\u4e4b\u5f8c<strong>\u8dd1 For\u8ff4\u5708 \u5224\u65b7\u6bcf\u4e00\u500b\u6578\u5b57\u6e1b\u6389\u524d K \u500b\u6578\u5b57\u7684\u6700\u5c0f\u503c\u6709\u6c92\u6709\u6bd4\u76ee\u524d\u6700\u5927\u503c (\u7b54\u6848) \u9084\u8981\u5927<\/strong>\uff0c\u53ef\u4ee5\u4f7f\u7528<strong>\u7dda\u6bb5\u6a39<\/strong>\u4f86\u7d00\u9304\u6bcf\u4e00\u500b\u5340\u6bb5\u7684\u6700\u5c0f\u503c\u4f86\u9632\u6b62\u8d85\u6642\u3002<\/p>\n\n\n\n<p class=\"\">\u53e6\u5916\uff0c\u5728\u9032\u884c<strong>\u7dda\u6bb5\u6a39\u641c\u5c0b<\/strong>\u7684\u6642\u5019\u4e5f\u53ef\u4ee5\u5728\u51fd\u5f0f\u4e2d\u5224\u65b7\u76ee\u524d <strong>For\u8ff4\u5708<\/strong> \u4e2d\u8dd1\u5230\u7684\u6578\u5b57\u6e1b\u6389\u76ee\u524d\u7bc0\u9ede\u7684\u503c\u662f\u5426\u6709\u5927\u65bc\u7b54\u6848\uff0c\u5982\u679c\u5c0f\u65bc\u7b49\u65bc\u7684\u8a71\u53ef\u4ee5\u76f4\u63a5 return \u51fd\u5f0f\u7bc0\u7701\u6642\u9593\u3002<strong>\u8a08\u7b97\u524d\u7db4\u548c\u53ca\u8a08\u7b97\u7b54\u6848\u7684\u6642\u5019\u53ef\u4ee5\u4f7f\u7528 Long Long Int \u4f86\u9632\u6b62\u8d85\u904e\u7bc4\u570d<\/strong>\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=f174\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge F174: \u86cb\u7cd5(Cake)<\/a><\/h3>\n\n\n\n<div class=\"hcb_wrap nfd-wb-animate nfd-wb-reveal-right nfd-delay-50\"><pre class=\"prism line-numbers lang-cpp\" data-lang=\"C++\"><code>#include &lt;iostream&gt;\n#include &lt;vector&gt;\nusing namespace std;\n\nlong long int tree[999999] = {}, ans;\nint N, K;\nvector&lt;long long int&gt;num;\n\nlong long int max(long long int a, long long int b)\n{\n    if (a &gt; b) return a;\n    return b;\n}\n\nlong long int build(int l, int r, int index)\n{\n    if (l == r)\n    {\n        tree[index] = num[l];\n        return num[l];\n    }\n    long long int left = build(l, (l+r)\/2, (index*2)+1);\n    long long int right = build(((l+r)\/2)+1, r, (index*2)+2);\n    tree[index] = min(left, right);\n    return tree[index];\n}\n\nlong long int query(int l, int r, int cl, int cr, int index, long long int value)\n{\n    if (value - tree[index] &lt; ans) return 999999999;\n    if (l == cl && r == cr) return tree[index];\n    if (cl == cr) return tree[index];\n    if (r &lt;= (cl+cr)\/2) return query(l, r, cl, (cl+cr)\/2, (index*2)+1, value);\n    else if (l &gt; (cl+cr)\/2) return query(l, r, ((cl+cr)\/2)+1, cr, (index*2)+2, value);\n    return min(query(l, r, cl, (cl+cr)\/2, (index*2)+1, value), query(l, r, ((cl+cr)\/2)+1, cr, (index*2)+2, value));\n}\n\nlong long int math(int l, int r, long long int value)\n{\n    return query(l, r, 0, N-1, 0, value);\n}\n\nlong long int calc(long long int hi, int l, int r)\n{\n    return hi - math(l, r, hi);\n}\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    cin &gt;&gt; N &gt;&gt; K;\n    long long int count = 0;\n    for (int i = 0; i&lt;N; i++)\n    {\n        long long int tmp;\n        cin &gt;&gt; tmp;\n        count += tmp;\n        num.push_back(count);\n    }\n    ans = num[0];\n    long long int hi = build(0, N-1, 0);\n    for (int i = 1; i&lt;K; i++)\n    {\n        ans = max(ans, calc(num[i], 0, i-1));\n    }\n    for (int i = K; i&lt;N; i++)\n    {\n        ans = max(ans, calc(num[i], i-K, i-1));\n    }\n    cout &lt;&lt; max(ans, 0) &lt;&lt; &quot;\\n&quot;;\n}\n\n\/\/ZeroJudge F174\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u5c0f\u660e\u904e\u751f\u65e5\uff0c\u5bb6\u4eba\u70ba\u4ed6\u6e96\u5099\u4e00\u500b\u9577\u65b9\u578b\u7684\u6c34\u679c\u86cb\u7cd5\uff0c\u7531\u65bc\u4ed6\u662f\u58fd\u661f\uff0c\u4ed6\u53ef\u4ee5\u5148\u5207\u86cb\u7cd5\u53bb\u5403\u3002\u9019\u500b\u86cb\u7cd5\u5206\u6210 N \u5c0f\u584a\uff0c\u6bcf\u584a\u90fd [&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,31,9,28],"class_list":["post-333","post","type-post","status-publish","format-standard","hentry","category-ioi-apcs","tag-20","tag-8","tag-13","tag-31","tag-9","tag-28"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/333","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=333"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/333\/revisions"}],"predecessor-version":[{"id":335,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/333\/revisions\/335"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=333"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=333"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=333"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}