B - Monthly Expense

POJ - 3273

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

Hint

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.

AC代码

#include <cstdio>
#include <iostream>
using namespace std;
int N,M;
const int inf=10000000;
int money[105000];
bool judge(int mid)
{int sum=0,num=0;for(int i=0;i<N;i++){if(sum+money[i]>mid){sum=money[i];num++;continue;}sum+=money[i];}return num<M;
}
int main()
{while(cin>>N>>M){int max1=0;for(int i=0;i<N;i++){cin>>money[i];if(money[i]>max1)max1=money[i];}int left=max1,right=inf;int mid=0;for(int i=0;i<100;i++){mid=(right+left)/2;if(judge(mid))right=mid;elseleft=mid;}cout<<right<<endl;}return 0;
}

Monthly Expense【二分】相关推荐

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

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

  2. Monthly expense(二分)

    又又又又是二分啦 憨憨桃子又来啦 题目链接:monthly expense 题目描述: Farmer John is an astounding accounting wizard and has r ...

  3. POJ3273:Monthly Expense(二分)

    Description Farmer John is an astounding accounting wizard and has realized he might run out of mone ...

  4. BZOJ 1639: [Usaco2007 Mar]Monthly Expense 月度开支( 二分答案 )

    直接二分答案然后判断. ----------------------------------------------------------------------------- #include&l ...

  5. bzoj 1639: [Usaco2007 Mar]Monthly Expense 月度开支(二分)

    1639: [Usaco2007 Mar]Monthly Expense 月度开支 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 1057  Solve ...

  6. Monthly Expense(二分)

    Monthly Expense Farmer John is an astounding accounting wizard and has realized he might run out of ...

  7. 二分搜索 POJ 3273 Monthly Expense

    题目传送门 1 /* 2 题意:分成m个集合,使最大的集合值(求和)最小 3 二分搜索:二分集合大小,判断能否有m个集合. 4 */ 5 #include <cstdio> 6 #incl ...

  8. bzoj1639[Usaco2007 Mar]Monthly Expense 月度开支*

    bzoj1639[Usaco2007 Mar]Monthly Expense 月度开支 题意: n天,每天有一个花费,现在要将它们分成连续的m段,要求所有段的总花费的最大值最小.求这个值.n,m≤10 ...

  9. USACO Monthly Expense

    洛谷 P2884 [USACO07MAR]每月的费用Monthly Expense https://www.luogu.org/problem/P2884 POJ 3273 Monthly Expen ...

最新文章

  1. 微生物测序样本准备方法总结
  2. 数据结构-顺序栈、链栈
  3. 启明云端分享| ESP8266\ESP32-C3\ESP32-C2三款芯片从核心系统、WIFI射频和基带、外围设备等都有哪些区别
  4. 根据谁创建资源授权资源
  5. html 图片导出excel,用JavaScript导出图片到Excel
  6. 分布式光伏补贴_2018年国家光伏并网补贴标准、政策
  7. iOS 离屏渲染的研究
  8. [转]解决2003不支持FLV的方法
  9. java里面的内存机制_Stack vs. Heap:了解 Java 的内存分配机制
  10. Linux安装deb安装包命令
  11. 三星s8android9,三星S8官方国行版安卓9固件rom刷机包:CHC-G9500ZCS3DSD5
  12. 情侣推送早安问候之小程序订阅通知模板推送 (出现在消息列表的服务通知)
  13. 40岁开始学编程,现在成了一名技术主管
  14. css3-简笔画 腾讯QQlogo
  15. 解决java虚拟机内存不足的错误 java.lang.OutOfMemoryError: PermGen space 没有文件TOMCAT_HOME/bin/catalina.sh
  16. 【PAT甲级】1142 Maximal Clique
  17. NOIP2016——蚯蚓
  18. 如何成为一个成熟男人
  19. 灰度共生矩阵-python
  20. ubuntu16.04 python版本切换以及pip工具基本知识点总结

热门文章

  1. php 内存队列,memcache构建简单的内存消息队列_PHP教程
  2. 大端字节序与小端字节序的转换
  3. 联想超融合平台oracle,联想AIO超融合云一体机解决方案.pdf
  4. matlab数字图像处理函数,MATLAB数字图像处理学习(二)|常用函数
  5. java按钮退出_java – 如何在此程序中添加退出按钮?怎么样“清楚”?
  6. 有人不会使用计算机的反义,现代汉语练习题及答案
  7. 二级考试c语言中 星号与字母 题型总结,2017年计算机二级考试C语言知识点归纳...
  8. java opencv orb_opencv python ORB算法
  9. ecshop清除mysql缓存_ECSHOP缓存清理关闭教程
  10. 串口 多个activity 安卓_Android-EasySerialPort