题目描述

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.

给出农夫在n天中每天的花费,要求把这n天分作m组,每组的天数必然是连续的,要求分得各组的花费之和应该尽可能地小,最后输出各组花费之和中的最大值

输入输出格式

输入格式:

Line 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

输出格式:

Line 1: The smallest possible monthly limit Farmer John can afford to live with.

输入输出样例

输入样例#1: 复制

7 5
100
400
300
100
500
101
400
输出样例#1: 复制

500

二分查找:
#include<cstdio>

#define max(a,b) (a>b?a:b) 

using namespace std;
],k,l=,r,mid,sum,maxx=-;
bool judge(int x){
    ,f=;
    ;i<=n;i++)
    {
        f+=m[i];
        ;
        if(f>x){
            ans++;f=;f+=m[i];
        }
    }if(ans<=k&&x>=maxx) return true;
    else return false;
}

int main()
{
    scanf("%d%d",&n,&k);
    ;i<=n;++i){
        scanf("%d",&m[i]);
        sum+=m[i];maxx=max(maxx,m[i]);
    }
    r=sum;
    while(l<=r){
        mid=(l+r)/;
        ) r=mid-;
        ;
    }printf("%d",l);
    ;
}

说明

If Farmer John schedules the months so that the first two days are a month, the third and fourth are a month, and the last three are their own months, he spends at most$500 in any month. Any other method of scheduling gives a larger minimum monthly limit.

P2884 [USACO07MAR]每月的费用Monthly Expense的更多相关文章

  1. bzoj1639 / P2884 [USACO07MAR]每月的费用Monthly Expense

    P2884 [USACO07MAR]每月的费用Monthly Expense 二分经典题 二分每个段的限制花费,顺便统计下最大段 注意可以分空段 #include<iostream> #i ...

  2. 洛谷—— P2884 [USACO07MAR]每月的费用Monthly Expense

    https://www.luogu.org/problemnew/show/P2884 题目描述 Farmer John is an astounding accounting wizard and ...

  3. [USACO07MAR]每月的费用Monthly Expense

    题目:POJ3273.洛谷P2884. 题目大意:有n个数,要分成m份,每份的和要尽可能小,求这个情况下和最大的一份的和. 解题思路:二分答案,对每个答案进行贪心判断,如果最后得出份数>m,则说 ...

  4. POJ-3273 Monthly Expense (最大值最小化问题)

    /* Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10757 Accepted: 4390 D ...

  5. BZOJ【1639】: [Usaco2007 Mar]Monthly Expense 月度开支

    1639: [Usaco2007 Mar]Monthly Expense 月度开支 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 700  Solved: ...

  6. POJ3273 Monthly Expense —— 二分

    题目链接:http://poj.org/problem?id=3273   Monthly Expense Time Limit: 2000MS   Memory Limit: 65536K Tota ...

  7. 【POJ 3273】 Monthly Expense (二分)

    [POJ 3273] Monthly Expense (二分) 一个农民有块地 他列了个计划表 每天要花多少钱管理 但他想用m个月来管理 就想把这个计划表切割成m个月来完毕 想知道每一个月最少花费多少 ...

  8. Divide and Conquer:Monthly Expense(POJ 3273)

    Monthly Expense 题目大意:不废话,最小化最大值 还是直接套模板,不过这次要注意,是最小化最大值,而不是最大化最小值,判断的时候要注意 联动3258 #include <iostr ...

  9. Monthly Expense(二分查找)

    Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17982 Accepted: 7190 Desc ...

随机推荐

  1. hive学习笔记-表操作

    Hive数据类型 基本数据类型 tinyint,smallint,int,biging,float,double,decimal,char,varchar,string,binary,boolean, ...

  2. python 验证码 高阶验证

    python 验证码 高阶验证 标签: 验证码python 2016-08-19 15:07 1267人阅读 评论(1) 收藏 举报  分类: 其他(33)    目录(?)[+]   字符型图片验证 ...

  3. LeetCode 451. Sort Characters By Frequency (根据字符出现频率排序)

    Given a string, sort it in decreasing order based on the frequency of characters. Example 1: Input: ...

  4. cocos2d的armature绑定到其它armature骨骼上的bug

    在cocos2dx中,rmature的骨骼上能够绑定另外的armature,在我的项目中使用了该功能来完毕骑乘功能,可是在使用过程发现了例如以下的bug,特写在这里做一下记录. </span&g ...

  5. getElementByTagName的使用

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. Scikit-learn库中的数据预处理:独热编码(二)

    在上一篇博客中介绍了数值型数据的预处理但是真实世界的数据集通常都含有分类型变量(categorical value)的特征.当我们讨论分类型数据时,我们不区分其取值是否有序.比如T恤尺寸是有序的,因为 ...

  7. Unity 代码改宏定义

    两个函数 PlayerSettings.GetScriptingDefineSymbolsForGroup(targetGroup); //所有宏定义 ; 分割 PlayerSettings.SetS ...

  8. C 语言程序员必读的 5 本书,你读过几本?

    你正通过看书来学习C语言吗?书籍是知识的丰富来源.你可以从书中学到各种知识.书籍可以毫无歧视地向读者传达作者的本意.C语言是由 Dennis Ritchie在1969年到1973年在贝尔实验室研发的. ...

  9. vue tab 点击请求方法

    页面: <Tabs value="name1" style="width: 100%;height: 900px;" @on-click="ge ...

  10. BZOJ 1137 半平面交

    半平面交的板子 //By SiriusRen #include <bits/stdc++.h> #define double long double using namespace std ...