Day3-N - Monthly Expense POJ3273
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
Lines 2.. N+1: Line i+1 contains the number of dollars Farmer John spends on the ith day
Output
Sample Input
7 5
100
400
300
100
500
101
400
Sample Output
500
Hint
const int maxm = ;
const int INF = 0x7fffffff; int n, buf[maxm], m; bool check(int d) {
int sum = , now = buf[];
for (int i = ; i < n; ++i) {
if(now + buf[i] <= d)
now += buf[i];
else {
now = buf[i];
++sum;
}
}
return sum <= m;
} int main() {
int l = -INF, r = , mid;
scanf("%d%d", &n, &m);
for(int i = ; i < n; ++i) {
scanf("%d", &buf[i]);
l = max(l, buf[i]);
r += buf[i];
}
while(l <= r) {
mid = (l + r) >> ;
if(check(mid))
r = mid - ;
else
l = mid + ;
}
printf("%d\n", l);
return ;
}
Day3-N - Monthly Expense POJ3273的更多相关文章
- POJ3273 Monthly Expense 2017-05-11 18:02 30人阅读 评论(0) 收藏
Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 25959 Accepted: 10021 ...
- POJ-3273 Monthly Expense (最大值最小化问题)
/* Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10757 Accepted: 4390 D ...
- POJ3273 Monthly Expense —— 二分
题目链接:http://poj.org/problem?id=3273 Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Tota ...
- 【POJ - 3273】Monthly Expense (二分)
Monthly Expense 直接上中文 Descriptions 给你一个长度为N的序列,现在要让你把他们切割成M份(所以每一份都是连续的),然后每一份都有一个和sum[i],其中最大的一个是ma ...
- Monthly Expense(最大值最小化问题)
POJ-3273 ...
- Divide and Conquer:Monthly Expense(POJ 3273)
Monthly Expense 题目大意:不废话,最小化最大值 还是直接套模板,不过这次要注意,是最小化最大值,而不是最大化最小值,判断的时候要注意 联动3258 #include <iostr ...
- Monthly Expense(二分查找)
Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17982 Accepted: 7190 Desc ...
- BZOJ1639: [Usaco2007 Mar]Monthly Expense 月度开支
1639: [Usaco2007 Mar]Monthly Expense 月度开支 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 529 Solved: ...
- POJ 3273 Monthly Expense(二分查找+边界条件)
POJ 3273 Monthly Expense 此题与POJ3258有点类似,一开始把判断条件写错了,wa了两次,二分查找可以有以下两种: ){ mid=(lb+ub)/; if(C(mid)< ...
随机推荐
- 整合SSM
SSM整合:Spring - SpringMVC - MyBatis 1.Spring - MyBatis : 需要整合:将MyBatis的SqlSessionFactory 交给Spr ...
- Vue父组件主动获取子组件的数据和方法
Vue父组件主动获取子组件的数据和方法 https://www.jianshu.com/p/bf88fc809131
- 简单实用的matlab柱状图显示比例及计数
这个小代码用于matlab柱状图显示比例及数值, 函数如下: function myhist(x) % myhist Codeby SimonLiang % Email:idignew@126.com ...
- Python - 同时运行两个以上的脚本
在c.py中 import os os.system("python a.py") os.system("python b.py")
- 为小学生出四则运算题目.java
import java.util.Scanner; import java.util.Random; public class test{ public static int s1 = new Ran ...
- NGINX学习积累(学习牛人)
大牛:http://www.cnblogs.com/zengkefu/p/5563608.html 当请求来临的时候,NGINX会选择进入虚拟主机,匹配location后,进入请求处理阶段. 在请求处 ...
- JS闭包(1)
1.首先看一段代码: var a = 1; function fn1(){ var b = 2; function fn2(){ console.log(a); console.log(b); } } ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 表格:让表格更加紧凑
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- Java基础 -3.3
位运算 指的是可以直接进行二进制数据的计算处理,主要是:与(&).或(|).非(!).异或(^).反码(~).移位处理(>>.<<) 与运算 public class ...
- 自定义更改 Xcode 新建 .h/.m 文件头部注释说明(文件名、工程名、作者、公司、版权等)信息
使用 Xcode 新建工程文件时,或默认生成一套注释说明信息在 .h/.m 文件的头部,说明了创建这个文件的名称.工程名.日期.作者.公司.版权等信息 // // ___FILENAME___ // ...