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 ≤ MN) 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.
题意:这题看了好久都没看懂题意,就是将序列划分为k段,要求找出k段中最大的资金和要在所有符合要求的划分中值最少
思路:我们可以直到这个值必然在所有数中最大值与所有数的总和之间,那么只要再这个区间进行二分即可
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int a[100005];
int main()
{
int n,m;
int sum,maxn,i,j,s,cnt,mid;
while(~scanf("%d%d",&n,&m))
{
sum = 0,maxn = 0;
for(i = 0; i<n; i++)
{
scanf("%d",&a[i]);
sum+=a[i];
maxn = max(maxn,a[i]);
}
while(maxn<sum)
{
mid = (sum+maxn)>>1;
s = 0,cnt = 0;
for(i = 0; i<n; i++)
{
s+=a[i];
if(s>mid)
{
s = a[i];
cnt++;
}
}
if(cnt<m) sum = mid;
else maxn = mid+1;
}
printf("%d\n",maxn);
}
return 0;
}

POJ3273: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(花销)-二分查找

    题意描述 给定n天的花销,把花销分成连续的m份,使得每一段时间花销和的最大值最小. 样例输入 7 5 100 400 300 100 500 101 400 样例输出 500 思路 设每天花销为exp ...

  4. POJ-3273 Monthly Expense 解题报告

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

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

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

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

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

  7. Monthly Expense(二分)

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

  8. Monthly Expense【二分】

    B - Monthly Expense POJ - 3273 Farmer John is an astounding accounting wizard and has realized he mi ...

  9. 二分搜索 POJ 3273 Monthly Expense

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

最新文章

  1. RxJava+Retrofit+OkHttp深入浅出-终极封装四(多文件下载之断点续传)
  2. 6大新品重磅发布,华为云全栈云原生技术能力持续创新升级
  3. 写论文与PPT汇报时matlab图片的背景透明处理
  4. Struts1 面试题目总结
  5. matlab 对角线相加,求和、转置和对角线 - MATLAB 系统中文帮助手册
  6. HAU寒假训练第一周
  7. P5656 【模板】二元一次不定方程 (exgcd)(公约数)
  8. CDC *pDC=GetDC();具体是什么意思?
  9. 番茄助手Assist X 快捷键
  10. 《大脑修复术》读书笔记
  11. 百度云服务器无法访问项目接口,互联网要点:百度云链接无法访问是怎么回事...
  12. docker入门级详解
  13. Kubernetes HPA测试
  14. awx,micaps,hdf,nc,radar,多普勒雷达,grib等各种数据解析,出图,计算等,有需要,欢迎联系.
  15. Visual Studio 卸载 Visual Assist番茄助手
  16. zz from newsmth e进制是信息表示的最优解
  17. 浏览器被劫持了 hao123
  18. 2022-3-22 Leetcode 207.课程表
  19. 数据结构与算法(四)-双向链表(DoublyLinkedList)
  20. Is there a small application abroad?

热门文章

  1. 营销人才必须具备狼性
  2. python爬取网页唯美图片
  3. SQL Server 处理百万级以上的数据处理与优化
  4. InnoDB Cluster详解
  5. Python计算小学奥数题正整数分解为几个整数的倍数和。
  6. Java Web 08_tomcatServlet
  7. PWmat助你提高2022基金命中率
  8. 多模态大语言模型综述来啦!一文带你理清多模态关键技术
  9. 运动蓝牙耳机哪个品牌好,2022运动蓝牙耳机推荐
  10. 2006最大热点:国内第一本Ajax图书1月上市,讲述最酷最炫的WEB2.0核心技术 ——亚马逊计算机排行榜首图书