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. 微信小程序日期定位弹出框遮挡问题

    只需要用bindtap绑定一个点击后的操作(隐藏键盘): wx.hideKeyboard()

  2. C++获取站点的ip地址

     #include "stdafx.h" #include <winsock2.h> #pragma comment (lib,"ws2_32.lib&q ...

  3. mysql 海量数据删除

    百度知道 - mysql删除海量数据   MySQL 数据库删除大批量数据的优化     看到这儿的话,最后看下这篇文章,对于操作海量数据的sql深入分析 cnblogs - 深度分析DROP,TRU ...

  4. SQL获取年月日方法

    方法一:利用DATENAME 在SQL数据库中,DATENAME(datetype,date)函数的作用是从日期中提取指定部分数据,其返回类型是nvarchar.datetype类型见附表1. SEL ...

  5. Unity3D总结:关于射线碰撞

    方法一:Physics.Raycast 光线投射 1.static function Raycast (origin : Vector3, direction : Vector3, distance  ...

  6. Linux问题,磁盘分区打不开了

    Metadata kept in Windows cache, refused to mount. chkdsk /f http://www.bubuko.com/infodetail-1184937 ...

  7. angularJS 自定义指令 分页

    原理和使用说明 1.插件源码主要基于angular directive来实现. 2.调用时关键地方是后台请求处理函数,也就是从后台取数据. 3.插件有两个关键参数currentPage.itemsPe ...

  8. Fedora25 下 OpenCV2.4.12 的安装

    你必须非常努力,才能看起来毫不费力.---------------感谢原作者的分享. opencv官网上面给出的 linux 下安装方式,基本上都是通过编译源码,即下载代码, cmake->ma ...

  9. C# - Garbage Collection

     The .NET Framework's garbage collector manages the allocation and release of memory for your appl ...

  10. 初识kbmmw 中的smartbind功能

    关于kbmmw smartbind 的开发原因及思路,大家可以参见官方的博客说明和红鱼儿的翻译. 今天我就实例操作一下,给大家演示一下具体实现. 我们新建一个工程 放几个基本的控件 在单元里面加上引用 ...