Monthly Expense,monthlyexpense

來源:互聯網
上載者:User

Monthly Expense,monthlyexpense
Problem Description

Farmer John is an astounding accounting wizard and has realized he might run out of money to run the farm. He has already calculated and recorded the exact amount of money (1 ≤ moneyi ≤ 10,000) that he will need to spend each day over the next N (1 ≤ N ≤ 100,000) days.

FJ wants to create a budget for a sequential set of exactly M (1 ≤ M ≤ N) fiscal periods called "fajomonths". Each of these fajomonths contains a set of 1 or more consecutive days. Every day is contained in exactly one fajomonth.

FJ's goal is to arrange the fajomonths so as to minimize the expenses of the fajomonth with the highest spending and thus determine his monthly spending limit.

 
InputLine 1: Two space-separated integers: N and M 
Lines 2..N+1: Line i+1 contains the number of dollars Farmer John spends on the ith day 
OutputLine 1: The smallest possible monthly limit Farmer John can afford to live with. 
Sample Input
7 5100400300100500101400
 
Sample Output
500
 
#include<iostream>#include<cstdio>using namespace std;int n,m;int a[100010];int fun(int s)   //fun函數是判斷當前的mid值能把n分成幾組{                //通過比較q與m的大小,對mid的值進行最佳化    int sum=0,q=1;    for(int i=1;i<=n;i++)//從第一天開始向下遍曆每天的花費    {        if(sum+a[i]<=s)//前第I天和<=mid時,把他們歸為這一組            sum+=a[i];        else//否則,第i天做為下一組的第一天        {            sum=a[i];            q++;//組數加一        }    }    if(q>m)//組數大於m,代表mid數值小了,        return 0;    return 1;//否則大了}int main(){    while(~scanf("%d%d",&n,&m)){        int l,r=0,mid,min=0,sum=0;        for(int i=1;i<=n;i++)        {            scanf("%d",&a[i]);            sum+=a[i];            if(a[i]>r)r=a[i];        }        l=sum;        int ans=0;        mid=(l+r)/2;        while(r<l)        {            if(!fun(mid))//如果mid偏小            {               r=mid+1;//下界上升            }            else//否則            {                l=mid-1;//上界下降            }             mid=(r+l)/2;        }        cout<<mid<<endl;    }    return 0;}



His monthly expense _________ 350 dollars

選C
A. total 作為“總計為”是 及物動詞 應去掉to
B. amount 作為“總計”是不及物動詞,與to 連用,而不是as
D. account 與for 連用可以表示“在數量上占。。。”例如:Children accounts for 12% of the US population.
 
Expend expense

花費支出;花錢
expend是動詞,花費的意思;expense是名詞,也是花費的意思,
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.