{"id":148,"date":"2026-03-17T15:07:36","date_gmt":"2026-03-17T07:07:36","guid":{"rendered":"https:\/\/blog.heroking2000.com\/?p=148"},"modified":"2026-03-17T15:10:54","modified_gmt":"2026-03-17T07:10:54","slug":"%e9%ab%98%e8%80%83%e5%bf%97%e6%84%bf%ef%bc%88%e5%bc%ba%e5%8c%96%e7%89%88%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.heroking2000.com\/?p=148","title":{"rendered":"\u9ad8\u8003\u5fd7\u613f\uff08\u5f3a\u5316\u7248\uff09"},"content":{"rendered":"\n<p>\u9898\u76ee\u63cf\u8ff0<\/p>\n\n\n\n<p>\u73b0\u6709 m \u6240\u5b66\u6821\uff0c\u6bcf\u6240\u5b66\u6821\u9884\u8ba1\u5206\u6570\u7ebf\u662f&nbsp;<math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"><semantics><mrow><msub><mi>a<\/mi><mi>i<\/mi><\/msub><\/mrow><\/semantics><\/math>\u200b\u3002\u6709 n \u4f4d\u5b66\u751f\uff0c\u4f30\u5206\u5206\u522b\u4e3a&nbsp;<math xmlns=\"http:\/\/www.w3.org\/1998\/Math\/MathML\"><semantics><mrow><msub><mi>b<\/mi><mi>i<\/mi><\/msub><\/mrow><\/semantics><\/math>\u3002<\/p>\n\n\n\n<p>\u6839\u636e n \u4f4d\u5b66\u751f\u7684\u4f30\u5206\u60c5\u51b5\uff0c\u5206\u522b\u7ed9\u6bcf\u4f4d\u5b66\u751f\u63a8\u8350\u4e00\u6240\u5b66\u6821\uff0c\u8981\u6c42\u5b66\u6821\u7684\u9884\u8ba1\u5206\u6570\u7ebf\u548c\u5b66\u751f\u7684\u4f30\u5206\u76f8\u5dee\u6700\u5c0f\uff08\u5206\u6570\u7ebf\u53ef\u9ad8\u53ef\u4f4e\uff0c\u6bd5\u7adf\u662f\u4f30\u5206\u561b\uff09\uff0c\u8fd9\u4e2a\u6700\u5c0f\u503c\u4e3a\u4e0d\u6ee1\u610f\u5ea6\u3002\u6c42\u6240\u6709\u5b66\u751f\u4e0d\u6ee1\u610f\u5ea6\u548c\u7684\u6700\u5c0f\u503c\u3002<\/p>\n\n\n\n<p>\u3010\u8f93\u5165\u683c\u5f0f\u3011<\/p>\n\n\n\n<p>\u7b2c\u4e00\u884c\u8bfb\u5165\u4e24\u4e2a\u6574\u6570 m,n\u3002m \u8868\u793a\u5b66\u6821\u6570\uff0cn \u8868\u793a\u5b66\u751f\u6570\u3002<br>\u7b2c\u4e8c\u884c\u5171\u6709 m \u4e2a\u6570\uff0c\u8868\u793a m \u4e2a\u5b66\u6821\u7684\u9884\u8ba1\u5f55\u53d6\u5206\u6570\u3002\u7b2c\u4e09\u884c\u6709 n \u4e2a\u6570\uff0c\u8868\u793a n \u4e2a\u5b66\u751f\u7684\u4f30\u5206\u6210\u7ee9\u3002<\/p>\n\n\n\n<p>\u3010\u8f93\u51fa\u683c\u5f0f\u3011<\/p>\n\n\n\n<p>\u8f93\u51fa\u4e00\u884c\uff0c\u4e3a\u6700\u5c0f\u7684\u4e0d\u6ee1\u610f\u5ea6\u4e4b\u548c\u3002<\/p>\n\n\n\n<p>\u3010\u8f93\u5165\u8f93\u51fa\u6837\u4f8b#1\u3011<\/p>\n\n\n\n<p>\u8f93\u5165#1<\/p>\n\n\n\n<p>\u590d\u5236<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">4 3\n513 598 567 689\n500 600 550<\/pre>\n\n\n\n<p>\u8f93\u51fa#1<\/p>\n\n\n\n<p>\u590d\u5236<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">32<\/pre>\n\n\n\n<p>\u3010\u6570\u636e\u8303\u56f4\u3011<\/p>\n\n\n\n<p>\u5bf9\u4e8e 80% \u7684\u6570\u636e\uff0c1 &lt;= n,m &lt;= 10000\uff0c\u4f30\u5206\u548c\u5f55\u53d6\u7ebf &lt;= 1000000\uff1b<br>\u5bf9\u4e8e 100% \u7684\u6570\u636e\uff0c1 &lt;= n,m &lt;= 200000\uff0c\u4f30\u5206\u548c\u5f55\u53d6\u7ebf &lt;= 1000000\uff1b<\/p>\n\n\n\n<p>\u3010\u4ee3\u7801\u6837\u4f8b\u3011<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;bits\/stdc++.h>\nusing namespace std;\nlong long  m,n,cnt;\nint a&#91;200005],b&#91;200005];\nint main(){   \n    cin>>m>>n;\n    for(int i=1;i&lt;=m;i++) cin>>a&#91;i];\n    for(int i=1;i&lt;=n;i++) cin>>b&#91;i];\n    sort(a+1,a+m+1);\n    \/\/sort(b+1,b+n+1);\n     \n    for(int i=1;i&lt;=n;i++){\n    \tauto x=lower_bound(a+1,a+m+1,b&#91;i])-a;\n    \tif(x==m+1) {\n    \t\tcnt+=abs(b&#91;i]-a&#91;m]);\n    \t} else if(x!=1) {\n    \t\tcnt+=min(abs(b&#91;i]-a&#91;x]),abs(b&#91;i]-a&#91;x-1]));\n    \t} else {\n    \t\tcnt=abs(b&#91;i]-a&#91;x]);\t\n    \t}\n    }\n    cout&lt;&lt;cnt&lt;&lt;endl;\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9898\u76ee\u63cf\u8ff0 \u73b0\u6709 m \u6240\u5b66\u6821\uff0c\u6bcf\u6240\u5b66\u6821\u9884\u8ba1\u5206\u6570\u7ebf\u662f&nbsp;ai\u200b\u3002\u6709 n \u4f4d\u5b66\u751f\uff0c\u4f30\u5206\u5206\u522b\u4e3a&nbsp;bi [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22],"tags":[24,25],"class_list":["post-148","post","type-post","status-publish","format-standard","hentry","category-oi","tag-24","tag-25"],"_links":{"self":[{"href":"https:\/\/www.heroking2000.com\/index.php?rest_route=\/wp\/v2\/posts\/148","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.heroking2000.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.heroking2000.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.heroking2000.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.heroking2000.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=148"}],"version-history":[{"count":2,"href":"https:\/\/www.heroking2000.com\/index.php?rest_route=\/wp\/v2\/posts\/148\/revisions"}],"predecessor-version":[{"id":150,"href":"https:\/\/www.heroking2000.com\/index.php?rest_route=\/wp\/v2\/posts\/148\/revisions\/150"}],"wp:attachment":[{"href":"https:\/\/www.heroking2000.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.heroking2000.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.heroking2000.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}