1482 - 划分
时间限制 : 10 秒
内存限制 : 1024 MB
输入
输出
样例
输入
输出
提示
5 0 5 1 7 9 9
247
10 0 5 6 7 7 4 6 2 13 19 9
1256
10000000 1 123 456 789 12345 6789 3 2000000 123456789 987654321 7000000 234567891 876543219 10000000 456789123 567891234
4972194419293431240859891640
|
【样例 1 解释】
最优的划分方案为 <span class="katex" style="font-size:1.21em;line-height:1.2;font-family:KaTeX_Main,;"><span class="katex-mathml">\{5,1\}, \{7\}, \{9\}, \{9\}</span><span class="katex-html"><span class="strut" style="vertical-align:-0.25em;"></span><span class="mopen">{</span><span class="mord">5</span><span class="mpunct">,</span><span class="mspace"></span><span class="mord">1</span><span class="mclose">}</span><span class="mpunct">,</span><span class="mspace"></span><span class="mopen">{</span><span class="mord">7</span><span class="mclose">}</span><span class="mpunct">,</span><span class="mspace"></span><span class="mopen">{</span><span class="mord">9</span><span class="mclose">}</span><span class="mpunct">,</span><span class="mspace"></span><span class="mopen">{</span><span class="mord">9</span><span class="mclose">}</span></span></span>。由 <span class="katex" style="font-size:1.21em;line-height:1.2;font-family:KaTeX_Main,;"><span class="katex-mathml">5 + 1 \leq 7 \leq 9 \leq 9</span><span class="katex-html"><span class="strut" style="vertical-align:-0.08333em;"></span><span class="mord">5</span><span class="mspace"></span><span class="mbin">+</span><span class="mspace"></span><span class="strut" style="vertical-align:-0.13597em;"></span><span class="mord">1</span><span class="mspace"></span><span class="mrel">≤</span><span class="mspace"></span><span class="strut" style="vertical-align:-0.13597em;"></span><span class="mord">7</span><span class="mspace"></span><span class="mrel">≤</span><span class="mspace"></span><span class="strut" style="vertical-align:-0.13597em;"></span><span class="mord">9</span><span class="mspace"></span><span class="mrel">≤</span><span class="mspace"></span><span class="strut" style="vertical-align:0em;"></span><span class="mord">9</span></span></span> 知该方案合法。
答案为 <span class="katex" style="font-size:1.21em;line-height:1.2;font-family:KaTeX_Main,;"><span class="katex-mathml">(5 + 1)^2 + 7^2 + 9^2 + 9^2 = 247</span><span class="katex-html"><span class="strut" style="vertical-align:-0.25em;"></span><span class="mopen">(</span><span class="mord">5</span><span class="mspace"></span><span class="mbin">+</span><span class="mspace"></span><span class="strut" style="vertical-align:-0.25em;"></span><span class="mord">1</span><span class="mclose"><span class="mclose">)</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="vertical-align:bottom;"><span><span class="pstrut"></span><span class="sizing reset-size6 size3 mtight" style="font-size:0.7em;"><span class="mord mtight">2</span></span></span></span></span></span></span></span><span class="mspace"></span><span class="mbin">+</span><span class="mspace"></span><span class="strut" style="vertical-align:-0.08333em;"></span><span class="mord"><span class="mord">7</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="vertical-align:bottom;"><span><span class="pstrut"></span><span class="sizing reset-size6 size3 mtight" style="font-size:0.7em;"><span class="mord mtight">2</span></span></span></span></span></span></span></span><span class="mspace"></span><span class="mbin">+</span><span class="mspace"></span><span class="strut" style="vertical-align:-0.08333em;"></span><span class="mord"><span class="mord">9</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="vertical-align:bottom;"><span><span class="pstrut"></span><span class="sizing reset-size6 size3 mtight" style="font-size:0.7em;"><span class="mord mtight">2</span></span></span></span></span></span></span></span><span class="mspace"></span><span class="mbin">+</span><span class="mspace"></span><span class="strut" style="vertical-align:0em;"></span><span class="mord"><span class="mord">9</span><span class="msupsub"><span class="vlist-t"><span class="vlist-r"><span class="vlist" style="vertical-align:bottom;"><span><span class="pstrut"></span><span class="sizing reset-size6 size3 mtight" style="font-size:0.7em;"><span class="mord mtight">2</span></span></span></span></span></span></span></span><span class="mspace"></span><span class="mrel">=</span><span class="mspace"></span><span class="strut" style="vertical-align:0em;"></span><span class="mord">2</span><span class="mord">4</span><span class="mord">7</span></span></span>。
虽然划分方案 <span class="katex" style="font-size:1.21em;line-height:1.2;font-family:KaTeX_Main,;"><span class="katex-mathml">\{5\}, \{1\}, \{7\}, \{9\}, \{9\}</span><span class="katex-html"><span class="strut" style="vertical-align:-0.25em;"></span><span class="mopen">{</span><span class="mord">5</span><span class="mclose">}</span><span class="mpunct">,</span><span class="mspace"></span><span class="mopen">{</span><span class="mord">1</span><span class="mclose">}</span><span class="mpunct">,</span><span class="mspace"></span><span class="mopen">{</span><span class="mord">7</span><span class="mclose">}</span><span class="mpunct">,</span><span class="mspace"></span><span class="mopen">{</span><span class="mord">9</span><span class="mclose">}</span><span class="mpunct">,</span><span class="mspace"></span><span class="mopen">{</span><span class="mord">9</span><span class="mclose">}</span></span></span> 对应的运行时间比 <span class="katex" style="font-size:1.21em;line-height:1.2;font-family:KaTeX_Main,;"><span class="katex-mathml">247</span><span class="katex-html"><span class="strut" style="vertical-align:0em;"></span><span class="mord">2</span><span class="mord">4</span><span class="mord">7</span></span></span> 小,但它不是一组合法方案,因为 <span class="katex" style="font-size:1.21em;line-height:1.2;font-family:KaTeX_Main,;"><span class="katex-mathml">5 \gt 1</span><span class="katex-html"><span class="strut" style="vertical-align:-0.0391em;"></span><span class="mord">5</span><span class="mspace"></span><span class="mrel">></span><span class="mspace"></span><span class="strut" style="vertical-align:0em;"></span><span class="mord">1</span></span></span>。
虽然划分方案 <span class="katex" style="font-size:1.21em;line-height:1.2;font-family:KaTeX_Main,;"><span class="katex-mathml">\{5\}, \{1,7\}, \{9\}, \{9\}</span><span class="katex-html"><span class="strut" style="vertical-align:-0.25em;"></span><span class="mopen">{</span><span class="mord">5</span><span class="mclose">}</span><span class="mpunct">,</span><span class="mspace"></span><span class="mopen">{</span><span class="mord">1</span><span class="mpunct">,</span><span class="mspace"></span><span class="mord">7</span><span class="mclose">}</span><span class="mpunct">,</span><span class="mspace"></span><span class="mopen">{</span><span class="mord">9</span><span class="mclose">}</span><span class="mpunct">,</span><span class="mspace"></span><span class="mopen">{</span><span class="mord">9</span><span class="mclose">}</span></span></span> 合法,但该方案对应的运行时间为 <span class="katex" style="font-size:1.21em;line-height:1.2;font-family:KaTeX_Main,;"><span class="katex-mathml">251</span><span class="katex-html"><span class="strut" style="vertical-align:0em;"></span><span class="mord">2</span><span class="mord">5</span><span class="mord">1</span></span></span>,比 <span class="katex" style="font-size:1.21em;line-height:1.2;font-family:KaTeX_Main,;"><span class="katex-mathml">247</span><span class="katex-html"><span class="strut" style="vertical-align:0em;"></span><span class="mord">2</span><span class="mord">4</span><span class="mord">7</span></span></span> 大。
【样例 2 解释】
最优的划分方案为 <span class="katex" style="font-size:1.21em;line-height:1.2;font-family:KaTeX_Main,;"><span class="katex-mathml">\{5\}, \{6\}, \{7\}, \{7\}, \{4,6,2\}, \{13\}, \{19,9\}</span><span class="katex-html"><span class="strut" style="vertical-align:-0.25em;"></span><span class="mopen">{</span><span class="mord">5</span><span class="mclose">}</span><span class="mpunct">,</span><span class="mspace"></span><span class="mopen">{</span><span class="mord">6</span><span class="mclose">}</span><span class="mpunct">,</span><span class="mspace"></span><span class="mopen">{</span><span class="mord">7</span><span class="mclose">}</span><span class="mpunct">,</span><span class="mspace"></span><span class="mopen">{</span><span class="mord">7</span><span class="mclose">}</span><span class="mpunct">,</span><span class="mspace"></span><span class="mopen">{</span><span class="mord">4</span><span class="mpunct">,</span><span class="mspace"></span><span class="mord">6</span><span class="mpunct">,</span><span class="mspace"></span><span class="mord">2</span><span class="mclose">}</span><span class="mpunct">,</span><span class="mspace"></span><span class="mopen">{</span><span class="mord">1</span><span class="mord">3</span><span class="mclose">}</span><span class="mpunct">,</span><span class="mspace"></span><span class="mopen">{</span><span class="mord">1</span><span class="mord">9</span><span class="mpunct">,</span><span class="mspace"></span><span class="mord">9</span><span class="mclose">}</span></span></span>。 <br />
来源
noip2019