POJ-3273 Monthly Expense two points

Source: Internet
Author: User

The main topic: there is a person's budget deficit, every day to pay a certain amount of money, altogether to still n days.
Now he asked to turn the N-day money into M-time, that is, do not have to pay every day, you can accumulate a certain number of days to pay off.
Now ask for M-time to drop the money, the maximum value of money to the smallest, ask this minimum is how much

Solving ideas: Minimum maximum, two-point solution
The minimum value of the enumeration is the maximum value of the money that is paid daily, and the maximum is the sum of the money that is paid daily.
Because each time the enumeration of money must be greater than or equal to the maximum value of the money per day, so can be divided into n sets, and then in the smallest collection, the minimum number of collections is each set to contain more days

#include <cstdio>#include <cstring>#include <algorithm>using namespace STD;#define MAXN 100010Long LongNum[maxn],sum, Min;intN, M;BOOLJudgeLong LongMID) {intCNT =1, Count;Long LongMoney =0; for(inti =0; i < N; i++) {money + = Num[i];if(Money > Mid) {Money =0;            i--;        cnt++; }    }if(CNT <= M)return true;return false;}Long LongSolve () {Long LongL = Min, r = Sum; while(L < R) {Long LongMid = (L + r)/2;if(Judge (mid)) R = mid-1;ElseL = mid +1; }returnl;}intMain () { while(scanf("%d%d", &n, &m)! = EOF) {Sum =0, Min =-1; for(inti =0; i < N; i++) {scanf("%lld", &num[i]);            min = max (min, num[i]);        Sum + = Num[i]; }printf("%lld\n", solve ()); }return 0;}

POJ-3273 Monthly Expense two points

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.