Monthly Expense, monthlyexpense

Source: Internet
Author: 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 nextN(1 ≤N≤ 100,000) days.

FJ wants to create a budget for a sequential set of exactlyM(1 ≤MN) 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: NAnd M 
Lines 2 .. N+ 1: Line I+ 1 contains the number of dollars Farmer John sort Ds on ITh day
OutputLine 1: The smallest possible monthly limit Farmer John can afford to live.
Sample Input
7 5100400300100500101400
 
Sample Output
500
 
# Include <iostream> # include <cstdio> using namespace std; int n, m; int a [100010]; int fun (int s) // The fun function is used to determine whether the current mid value can divide n into several groups {// optimize the mid value int sum = 0 by comparing the size of q and m, q = 1; for (int I = 1; I <= n; I ++) // traverse the daily spending from the first day to the next {if (sum + a [I] <= s) // The first day and <= mid, classify them into this group sum + = a [I]; else // otherwise, the day I serves as the first day of the next group {sum = a [I]; q ++; // number of groups plus one }}if (q> m) // if the number of groups is greater than m, it indicates that the value of mid is smaller, return 0; return 1; // otherwise it is larger} int main () {while (~ Scanf ("% 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) // If the mid is too small {r = mid + 1; // the lower bound is increased} else // otherwise {l = mid-1; // lower upper bound} mid = (r + l)/2;} cout <mid <endl;} return 0 ;}



His monthly expense _________ 350 dollars

Select C
A. As "total is", total should be removed from
B. amount, as "Total", is an inactive verb used with to instead of
D. account and for can be used together to indicate "count in quantity ..." Example: Children accounts for 12% of the US population.

Expend expense

Spending; spending
Expend is a verb and the meaning of spending. expense is a noun and also a meaning of spending,

Related Article

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.