bzoj1639[usaco2007 mar]monthly Expense Monthly Expenses *

Source: Internet
Author: User

bzoj1639[usaco2007 mar]monthly Expense Monthly expenditure

Test instructions

N days, there is a cost per day, and now it is necessary to divide them into successive m segments, requiring the total cost of all segments to be minimized. To find this value. n,m≤100000

Exercises

Two cents spent, less than two points of the day as a paragraph. Note that the lower bound of the dichotomy should be the maximum value spent per day.

Code:

1#include <cstdio>2#include <cstring>3#include <algorithm>4 #defineMAXN 1001005 #defineInc (I,J,K) for (int i=j;i<=k;i++)6 using namespacestd;7 8InlineintRead () {9     CharCh=getchar ();intf=1, x=0;Ten      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; Ch=GetChar ();} One      while(ch>='0'&&ch<='9') x=x*Ten+ch-'0', ch=GetChar (); A     returnf*x; - } - intN,m,mon[maxn],l,r,ans; the BOOLCheckintx) { -     inty=1, z=0; -Inc (I,1, N) { -         if(z+mon[i]>x) {y++; z=mon[i];if(y>m)return 0;}Elsez+=Mon[i]; +     } -     return 1; + } A intMain () { atN=read (); M=read (); Inc (I,1, n) mon[i]=read (), L=max (L,mon[i]), r+=Mon[i]; -      while(l<=R) { -         intMid= (l+r) >>1;if(Check (mid)) ans=mid,r=mid-1;ElseL=mid+1; -     } -printf"%d", ans);return 0; -}

20160731

bzoj1639[usaco2007 mar]monthly Expense Monthly Expenses *

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.