Monthly Expense
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 20603   Accepted: 8101

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.

Input

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

Output

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

Sample Input

7 5
100
400
300
100
500
101
400

Sample Output

500
题意:将N个数分成M组,使每组之和的最大值最小。
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN=;
int n,m;
int spe[MAXN];
bool test(int mon)
{
int s=;
int sum=;
for(int i=;i<n;i++)
{
if(spe[i]>mon) return false;
if(sum+spe[i]<=mon)
{
sum+=spe[i];
}
else
{
sum=spe[i];
s++;
}
}
s++;
return s<=m;
}
int main()
{
while(cin>>n>>m)
{
for(int i=;i<n;i++)
{
cin>>spe[i];
}
int l=;
int r=0x3f3f3f3f;
while(r-l>)
{
int mid=(l+r)>>;
if(test(mid)) r=mid;
else l=mid;
}
cout<<r<<endl;
}
return ;
}

POJ3273(最大化问题)的更多相关文章

  1. ubuntu终端窗口最大化(不是全屏)

    窗口最大化:ctrl+win窗+↑ 窗口还原:ctrl+win窗+↓ 这快捷键让人无语.好好的gnome被改造成unity,快捷键也改掉了.win窗+↑/↓为啥不用呢? 还有就是terminal的ta ...

  2. Winform窗体最大化的时候,如何指定窗体的位置、大小

    一.重写窗体的SizeChanged事件不能改变窗体最大化的位置和大小. public partial class Form2 : Form { public Form2() { Initialize ...

  3. Easyui 让Window弹出居中与最大化后居中

    easyui1.3.2版本,window的弹出不会居中了.而dialog是会居中的,我们必须为为window的open事件做扩展 代码如下:只要加入以下代码即可.如果你是看了MVC项目系列的,把他放到 ...

  4. 【荐2】Total Commander 7.57 配置选项 个性化设置备份,,,开启时如何自动最大化???(二)

    最近安装了下新版的“Total Commander 7.56”,发现它的默认设置是如此的不好用,现把对其个性化设置备份如下(符合大部分用户的操作习惯): 默认打开Total Commander 7.5 ...

  5. C# WinForm 禁止最大化、最小化、双击标题栏、双击图标等操作(转载)

    protected override void WndProc(ref Message m) { if (m.Msg==0x112) { switch ((int) m.WParam) { //禁止双 ...

  6. VC++ 如何使窗体最大化或是最小化

    最大化最小的使得的函数是 ShowWindow函数 ShowWindow(SW_SHOWMINIMIZED);//最小化 ShowWindow(SW_SHOWMAXIMIZED);//最大化 Show ...

  7. ACM Yougth的最大化

    Yougth的最大化 时间限制:1000 ms  |  内存限制:65535 KB 难度:4   描述 Yougth现在有n个物品的重量和价值分别是Wi和Vi,你能帮他从中选出k个物品使得单位重量的价 ...

  8. winform窗体最大化、最小化、还原

    //最大化 private void button_maxsize_Click(object sender, EventArgs e)        {            this.WindowS ...

  9. wpf 自定义窗口,最大化时不覆盖任务栏

    相信很多人使用wpf时会选择自定义美观的窗口,因此会设置WindowStyle="None" 取消自带的标题栏.但这样使用 WindowState="Maximized& ...

随机推荐

  1. nginx list directory

    使用 http autoindex 模块列出 目录, 例如 需要将 /var/www 下的 resourcepacks 目录以 http 的方式 暴露         这样设置 nginx       ...

  2. Spring.net1.3.1+Nhibernate3.0+Mysql/Access/SqlServer/Oracel/SQlite

    详情请看我的博文:http://www.ruisoftcn.com/blog/article.asp?id=999

  3. response响应和User-Agent历史

    返回百度的源码,没有任何伪装: response是服务器响应的类文件,除了支持文件操作的方法以外,还支持以下方法:

  4. 这6种思维,学会了你就打败了95%文案!zz

    ​本文笔者为大家讲述了文案高手写文案时最常用的六种思维,这六种思维也都是文案新手容易入的坑. 有的人做了3,5年的文案,还是小白一个.而有的人短短1,2年的时间,却可以成为文案高手. 为什么? 我总结 ...

  5. Protostuff具体解释

    Protostuff具体解释 作者:chszs,未经博主同意不得转载. 经许可的转载需注明作者和博客主页:http://blog.csdn.net/chszs 一.Protostuff介绍 Proto ...

  6. 【TensorFlow-windows】(三) 多层感知器进行手写数字识别(mnist)

    主要内容: 1.基于多层感知器的mnist手写数字识别(代码注释) 2.该实现中的函数总结 平台: 1.windows 10 64位 2.Anaconda3-4.2.0-Windows-x86_64. ...

  7. 百度之星2016资格赛D,水题

    很简单的题,主要是要用字符串哈希,把字符串处理成整数.接下来可以继续用hash,也可以像我一样用个map就搞定了. /* * Author : ben */ #include <cstdio&g ...

  8. Elasticsearch + Logstash + Kibana 搭建教程

    # ELK:Elasticsearch + Logstash + Kibana 搭建教程 Shipper:日志收集者.负责监控本地日志文件的变化,及时把日志文件的最新内容收集起来,输出到Redis暂存 ...

  9. 九度OJ 1089:数字反转 (数字反转)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3059 解决:1678 题目描述: 12翻一下是21,34翻一下是43,12+34是46,46翻一下是64,现在又任意两个正整数,问他们两个 ...

  10. 使用JavaScript获取浏览器UserAgent

    可以在浏览器地址栏输入about:version来查看UserAgent等信息 但是在Win10系统,本人亲测,IE和Edge用这样的方式都获取不到信息 在我惯用的QQ浏览器上倒是可以获取到 为了能方 ...