{"id":1122,"date":"2024-08-23T09:00:00","date_gmt":"2024-08-23T01:00:00","guid":{"rendered":"https:\/\/seanxd.com\/?p=1122"},"modified":"2024-07-24T11:12:00","modified_gmt":"2024-07-24T03:12:00","slug":"zerojudge-b231","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-b231\/","title":{"rendered":"ZeroJudge B231: Book"},"content":{"rendered":"\n\n\n<p>\u73fe\u6709 N \u672c\u66f8\u9700\u5370\u5237\u88dd\u8a02\u3002\u6bcf\u4e00\u672c\u66f8\u5fc5\u9808\u5148\u5370\u5237\u518d\u88dd\u8a02\u3002\u5de5\u5ee0\u6709 N \u53f0\u88dd\u8a02\u6a5f\u4f46\u53ea\u6709\u4e00\u53f0\u5370\u5237\u6a5f\u3002\u5370\u5237\u6a5f\u540c\u6642\u53ea\u80fd\u5370\u4e00\u672c\u66f8\uff0c\u800c\u4e14\u5fc5\u9700\u5370\u5b8c\u4e00\u672c\u66f8\u5f8c\u624d\u80fd\u5370\u4e0b\u4e00\u672c\u66f8\u3002\u73fe\u7d66\u5b9a\u6bcf\u4e00\u672c\u66f8\u7684\u5370\u5237\u6642\u9593\u548c\u88dd\u8a02\u6642\u9593\uff0c\u8acb\u8a08\u7b97\u6240\u6709\u66f8\u6700\u5feb\u8981\u591a\u4e45\u624d\u80fd\u5370\u5237\u88dd\u8a02\u5b8c\u7562\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\u8f38\u5165\u7b2c\u4e00\u884c\u70ba N\uff0c\u5373\u66f8\u7684\u6578\u76ee (1 &lt;= N &lt;= 1000)\u3002<br>\u4ee5\u4e0b N \u884c\u6bcf\u884c\u4ee3\u8868\u4e00\u672c\u66f8\uff0c\u6bcf\u884c\u6709\u5169\u500b\u6578\u5b57\u3002\u7b2c\u4e00\u500b\u6578\u5b57\u4ee3\u8868\u66f8\u7684\u5370\u5237\u6642\u9593\uff0c\u7b2c\u4e8c\u500b\u6578\u5b57\u4ee3\u8868\u66f8\u7684\u88dd\u8a02\u6642\u9593\uff0c\u6642\u9593\u90fd\u4ecb\u65bc 1 \u5230 1000 \u4e4b\u9593\u3002<\/td><td>\u8f38\u51fa\u6240\u6709\u66f8\u6700\u5feb\u5370\u5237\u88dd\u8a02\u5b8c\u7562\u7684\u6642\u9593\u3002<\/td><\/tr><tr><td>2<br>5 2<br>1 1<br>2<br>10 9<br>9 8<\/td><td>7<br>27<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u89e3\u984c\u601d\u8def<\/h2>\n\n\n\n<p>\u4f7f\u7528 Pair&lt;int, int> \u4f86\u6536\u8cc7\u6599\uff0c\u53ea\u662f\u8981\u5c07\u8cc7\u6599\u53cd\u904e\u4f86\u5b58\uff0c\u5370\u5237\u6642\u9593\u5b58\u5728 second\uff0c\u88dd\u8a02\u6642\u9593\u5247\u5b58\u5728 first\u3002\u6536\u5b8c\u8cc7\u6599\u4e4b\u5f8c\u8981\u5c07 Pair \u9663\u5217\u9032\u884c\u6392\u5e8f\uff0c\u7136\u5f8c\u8dd1 For\u8ff4\u5708 \u5f9e N-1 \u5230 0\uff0c\u8981\u5f9e\u300c\u88dd\u8a02\u6642\u9593\u6700\u5927\u300d\u7684\u8cc7\u6599\u958b\u59cb\u505a\u8655\u7406\u3002<\/p>\n\n\n\n<p>\u8a2d\u5b9a\u5169\u500b\u8b8a\u6578 ans \u548c start\uff0c\u90fd\u9810\u8a2d\u70ba 0\u3002\u6bcf\u6b21\u9032\u5230 For\u8ff4\u5708 \u6642\uff0c\u90fd\u8981\u5c07 start += \u76ee\u524d\u8cc7\u6599\u7684\u5370\u5237\u6642\u9593\uff0cstart \u662f\u6307\u6240\u6709\u8cc7\u6599\u6240\u9700\u7684\u5370\u5237\u6642\u9593\uff0c\u56e0\u70ba\u5370\u5237\u6a5f\u53ea\u6709\u4e00\u81fa\u3002\u7136\u5f8c\u8981\u8a08\u7b97 start + \u88dd\u8a02\u6642\u9593\u662f\u591a\u5c11\uff0c\u4e26\u4e14\u548c\u76ee\u524d\u7684 ans \u505a\u6700\u5927\u503c\u7684\u6bd4\u8f03\uff0cans \u5c31\u662f\u6bcf\u6b21\u7684\u5370\u5237\u7e3d\u6642\u9593 + \u73fe\u5728\u7684\u88dd\u8a02\u6642\u9593\u6700\u5927\u503c\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=b231\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge B231: \u66f8<\/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;algorithm&gt;\nusing namespace std;\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    int N;\n    while (cin &gt;&gt; N) {\n        pair&lt;int, int&gt; dom[5000] = {};\n        for (int i = 0; i&lt;N; i++) cin &gt;&gt; dom[i].second &gt;&gt; dom[i].first;\n        sort(dom, dom+N);\n        int ans = 0, start = 0;\n        for (int i = N-1; i&gt;=0; i--) {\n            start += dom[i].second;\n            int tmp = start + dom[i].first;\n            ans = max(tmp, ans);\n        }\n        cout &lt;&lt; ans &lt;&lt; &quot;\\n&quot;;\n    }\n}\n\n\/\/ZeroJudge B231\n\/\/Dr. SeanXD<\/code><\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u73fe\u6709 N \u672c\u66f8\u9700\u5370\u5237\u88dd\u8a02\u3002\u6bcf\u4e00\u672c\u66f8\u5fc5\u9808\u5148\u5370\u5237\u518d\u88dd\u8a02\u3002\u5de5\u5ee0\u6709 N \u53f0\u88dd\u8a02\u6a5f\u4f46\u53ea\u6709\u4e00\u53f0\u5370\u5237\u6a5f\u3002\u5370\u5237\u6a5f\u540c\u6642\u53ea\u80fd\u5370\u4e00\u672c [&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":[23,20,19,9],"class_list":["post-1122","post","type-post","status-publish","format-standard","hentry","category-ioi-apcs","tag-pair","tag-20","tag-19","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1122","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=1122"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1122\/revisions"}],"predecessor-version":[{"id":1124,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/1122\/revisions\/1124"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=1122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=1122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=1122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}