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是名詞,也是花費的意思,