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 ;
}

最新文章

  1. Neural Network Toolbox使用笔记1:数据拟合
  2. Jmeter发送Java请求
  3. 表单验证代码实例:jquery.validate.js表单验证插件
  4. ecshop搜索出现相关商品的效果滑动下拉效果
  5. CG绘画笔记
  6. 【Apache运维基础(2)】主配置文件说明
  7. 浅谈KMP算法及其next[]数组
  8. selenuim ide回放时出现的问题
  9. httpd与tomcat基于mod_jk整合
  10. iOS提交AppStore后申请加急审核(转)
  11. spring mvc下shiro的session,request等问题
  12. Git基本操作命令2
  13. 原生JavaScript实现焦点图轮播
  14. ionic2+Angular2:套接口明细步骤,以登录功能为例
  15. Redis服务启动失败,提示:redis-server:command not found
  16. 我的python之路
  17. j.u.c系列(07)---之读写锁:ReentrantReadWriteLock
  18. Spring Bean 的加载顺序
  19. 在Android中,px,dp,dip,sp的不同之处
  20. 如何利用Visio设计一个系统的结构图

热门文章

  1. 【翻译自mos文章】检查$ORACLE_HOME是否是RAC的HOME的方法以及relink RAC的Oracle binary的方法
  2. 配置mysql主从服务器
  3. pycharm pull到github
  4. 小白学phoneGap《构建跨平台APP:phoneGap移动应用实战》连载一(PhoneGap中的API)
  5. 转:Hadoop和Spark的异同
  6. 【java读书笔记】——Collection集合之六大接口(Collection、Set、List、Map、Iterator和Comparable)
  7. python(4)- 简单练习:python实现购物车的优化
  8. js replace 全局替换 以表单的方式提交参数 判断是否为ie浏览器 将jquery.qqFace.js表情转换成微信的字符码 手机端省市区联动 新字体引用本地运行可以获得,放到服务器上报404 C#提取html中的汉字 MVC几种找不到资源的解决方式 使用Windows服务定时去执行一个方法的三种方式
  9. Cocos2d-x 3.0final 终结者系列教程15-win7+vs2012+adt+ndk环境搭建(无Cygwin)
  10. 华为P7电信4G版刷机包 EMUI2.3 官方B125 第3版 精简 ROOT