题目描述

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. HDU1171_Big Event in HDU【01背包】

    Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  2. CoffeeScript里的字符串插值

    拼接字符串是我们常干的事情.与其用很多的 "" + "",不如用一下字符串插值,可读性好些. 方法是在字符串中加入#{ 变量.表达式.函数等} getOther ...

  3. table形式的列表页面显示

    (该案例在项目中的reserve_bchmc.html,其对应的后台在CountBean中) 先看一下效果图: 该列表页面并不是用easyUI中的datagrid实现的,而是用table实现页面显示的 ...

  4. How to: Set Properties of Web Application Projects

    https://msdn.microsoft.com/library/aa983454(v=vs.100).aspx ASP.NET Web application projects share th ...

  5. RxJava使用介绍

    主讲人:阳石柏 RxJava基本概念 背压概念介绍 RxJava 2.0版本介绍及更新 一.RxJava基本概念 RxJava 在 GitHub 主页上的自我介绍是 “a library for co ...

  6. bzoj2744 [HEOI2012]朋友圈——二分图匹配

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2744 首先,求一个图的最大团等价于求它的补图的最大独立集,而二分图的最大独立集 = 总点数 ...

  7. Spark SQL读parquet文件及保存

    import org.apache.spark.{SparkConf, SparkContext} import org.apache.spark.sql.{Row, SparkSession} im ...

  8. SCOI2014题解

    SCOI2014由极不靠谱的电子坑爹大学出题.电子坑爹大学打破了多年行规,暴力+NOIP500分居然不能进队.极其逗比的第一天暴力给10分!!还好有些题不是很难,省队爷分数大概在150以上(最高420 ...

  9. ACM_三元一次函数解法(克莱姆法则)

    三元一次函数 Time Limit: 2000/1000ms (Java/Others) Problem Description: 计算三元一次函数..如图 Input: EOF,先输入n,表示样例个 ...

  10. Unity 引擎UGUI之自定义树形菜单(TreeView)

    先上几张效果图:          如果你需要的也是这种效果,那你就来对地方了! 目前,我们这个树形菜单展现出来的功能如下: 1.可以动态配置数据源: 2.点击每个元素的上下文菜单按钮(也就是图中的三 ...