传送门

Time Limit: 2000MS  Memory Limit: 65536K

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.

Source

===============================
做题只是为了确认自己仍然SB
===============================
WA
#include <cstdio>
using namespace std; const int N(1e5+);
int a[N];
int oo=1e9+;
int n, m;
bool C(int x){
int s=, c=;
for(int i=; i<n; i++)
s+a[i]>x ? s=a[i], c++ : s+=a[i];
return ++c<=m;
}
int main(){
scanf("%d%d", &n, &m);
for(int i=; i<n; i++)
scanf("%d", a+i);
int l=, r=oo, mid;
for(; r-l>; mid=(l+r)>>, C(mid)?r=mid:l=mid);
while(r-l!=);
printf("%d\n", r);
}

AC

#include <cstdio>
using namespace std; const int N(1e5+);
int a[N];
int oo=1e9+;
int n, m;
bool C(int x){
int s=, c=;
for(int i=; i<n; i++){
if(a[i]>x) return ;
s+a[i]>x ? s=a[i], c++ : s+=a[i];
}
return ++c<=m;
}
int main(){
scanf("%d%d", &n, &m);
for(int i=; i<n; i++)
scanf("%d", a+i);
int l=, r=oo, mid;
for(; r-l>; mid=(l+r)>>, C(mid)?r=mid:l=mid);
while(r-l!=);
printf("%d\n", r);
}

POJ 3273 Monthly Expense的更多相关文章

  1. POJ 3273 Monthly Expense(二分查找+边界条件)

    POJ 3273 Monthly Expense 此题与POJ3258有点类似,一开始把判断条件写错了,wa了两次,二分查找可以有以下两种: ){ mid=(lb+ub)/; if(C(mid)< ...

  2. 二分搜索 POJ 3273 Monthly Expense

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

  3. POJ 3273 Monthly Expense二分查找[最小化最大值问题]

    POJ 3273 Monthly Expense二分查找(最大值最小化问题) 题目:Monthly Expense Description Farmer John is an astounding a ...

  4. [ACM] POJ 3273 Monthly Expense (二分解决最小化最大值)

    Monthly Expense Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14158   Accepted: 5697 ...

  5. POJ 3273 Monthly Expense(二分答案)

    Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 36628 Accepted: 13620 Des ...

  6. poj 3273 Monthly Expense(贪心+二分)

    题目:http://poj.org/problem?id=3273 题意:把n个数分成m份,使每份的和尽量小,输出最大的那一个的和. 思路:二分枚举最大的和,时间复杂度为O(nlog(sum-max) ...

  7. POJ 3273 Monthly Expense 二分枚举

    题目:http://poj.org/problem?id=3273 二分枚举,据说是经典题,看了题解才做的,暂时还没有完全理解.. #include <stdio.h> #include ...

  8. poj 3273 Monthly Expense (二分搜索,最小化最大值)

    题目:http://poj.org/problem?id=3273 思路:通过定义一个函数bool can(int mid):=划分后最大段和小于等于mid(即划分后所有段和都小于等于mid) 这样我 ...

  9. POJ 3273 Monthly Expense(二分搜索)

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

随机推荐

  1. vue中如何不通过路由直接获取url中的参数

    前言:为什么要不通过路由直接获取url中的参数? vue中使用路由的方式设置url参数,但是这种方式必须要在路径中附带参数,而且这个参数是需要在vue的路由中提前设置好的. 相对来说,在某些情况下直接 ...

  2. Mybaits学习总结2

    http://www.cnblogs.com/xdp-gacl/p/4262895.html 继续参考这篇文章写Mybaits学习总结 上一章,我修改了编码,统一为UTF8之后,便没有编码错误 < ...

  3. YII获取刚插入数据的id主键

    单条数据时model->attributes['id']; 循环插入时使用 Yii::app()->db->getLastInsertID() 获取 循环插入时需要每次插入后重置 m ...

  4. ArcGIS Engine 中 线加箭头

            ;             ICartographicLineSymbol pCartoLineSymbol = );             IArrowMarkerSymbol p ...

  5. 关于Java多态

    什么是多态 同一个实现接口,使用不同的实例而执行不同的操作 子类转换成父类的规则: *将一个父类的引用指向一个子类对象时,称为上转型,自动进行类型转换 *此时通过父类引用变量调用的方法是子类覆盖或继承 ...

  6. WPF技巧-Canvas转为位图

    转自:http://www.cnblogs.com/tmywu/archive/2010/09/14/1825650.html 在WPF中我们可以将Canvas当成一种画布,将Canvas中的控件当成 ...

  7. Studying-Swift :Day01

    学习地址:http://www.rm5u.com/    或    http://www.runoob.com/ 如果创建的是 OS X playground 需要引入 Cocoa;  如果我们想创建 ...

  8. C语言 文件操作11--文件函数再讲 fseek()和ftell()

    //文件函数再讲 //fseek(),ftell(), #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdl ...

  9. SilverLight自定义ImageButton

    SilverLight中XAML的写法和WPF一样,但是发现在自定义按钮上,没有WPF来的容易,下面说说我制作SilverLight中的ImageButton的一些思路. 在SilverLight中, ...

  10. Bootstrap Paginator 分页插件参数介绍及使用

    Bootstrap Paginator是一款基于Bootstrap的js分页插件,功能很丰富,个人觉得这款插件已经无可挑剔了.它提供了一系列的参数用来支持用户的定制,提供了公共的方法可随时获得插件状态 ...