POJ3273 Monthly Expense 2017-05-11 18:02 30人阅读 评论(0) 收藏
Monthly Expense
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 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 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 |
——————————————————————————————————
题目的意思是给出n个数,分成5组,要求每组之和最大值最小是多少
思路:二分+验证
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define inf 0x3f3f3f3f
#define LL long long LL a[100005];
int n,m;
bool ok(LL x)
{
LL sum=0;
int cnt=0;
for(int i=0; i<n; i++)
{
sum+=a[i];
if(sum>x)
{
cnt++;
sum=a[i];
}
}
if(sum>0)
cnt++;
if(cnt<=m)
return 1;
return 0;
} int main()
{ while(~scanf("%d%d",&n,&m))
{
LL mx=0;
LL sum=0;
for(int i=0; i<n; i++)
{
scanf("%lld",&a[i]);
mx=max(mx,a[i]);
sum+=a[i];
} LL l=mx,r=sum;
LL ans;
while(l<=r)
{
LL mid=(l+r)/2;
if(ok(mid))
{
r=mid-1;
ans=mid;
}
else
{
l=mid+1;
}
}
printf("%lld\n",ans);
}
return 0;
}
POJ3273 Monthly Expense 2017-05-11 18:02 30人阅读 评论(0) 收藏的更多相关文章
- HDU6024 Building Shops 2017-05-07 18:33 30人阅读 评论(0) 收藏
Building Shops Time Limit: 2000/1000 MS ...
- 关于serialVersionUID的说明 分类: B1_JAVA 2014-05-24 11:02 1334人阅读 评论(0) 收藏
1.为什么要使用serialVersionUID (1)对于实现了Serializable接口的类,可以将其序列化输出至磁盘文件中,同时会将其serialVersionUID输出到文件中. (2)然后 ...
- 移植QT到ZedBoard(制作运行库镜像) 交叉编译 分类: ubuntu shell ZedBoard OpenCV 2014-11-08 18:49 219人阅读 评论(0) 收藏
制作运行库 由于ubuntu的Qt运行库在/usr/local/Trolltech/Qt-4.7.3/下,由makefile可以看到引用运行库是 INCPATH = -I/usr//mkspecs/d ...
- Rebuild my Ubuntu 分类: ubuntu shell 2014-11-08 18:23 193人阅读 评论(0) 收藏
全盘格式化,重装了Ubuntu和Windows,记录一下重新配置Ubuntu过程. //build-essential sudo apt-get install build-essential sud ...
- MS SQLServer 批量附加数据库 分类: SQL Server 数据库 2015-07-13 11:12 30人阅读 评论(0) 收藏
************************************************************ * 标题:MS SQLServer 批量附加数据库 * 说明:请根据下面的注释 ...
- The Happy Worm 分类: POJ 排序 2015-08-03 18:57 5人阅读 评论(0) 收藏
The Happy Worm Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 4698 Accepted: 1047 Descr ...
- Hdu 1009 FatMouse' Trade 2016-05-05 23:02 86人阅读 评论(0) 收藏
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tot ...
- OC基础:数组.字典.集 分类: ios学习 OC 2015-06-18 18:58 47人阅读 评论(0) 收藏
==============NSArray(不可变数组)=========== NSArray,继承自NSObject 用来管理(储存)一些有序的对象,不可变数组. 创建一个空数组 NSArray ...
- HDU6027 Easy Summation 2017-05-07 19:02 23人阅读 评论(0) 收藏
Easy Summation Time Limit: 2000/1000 MS ...
随机推荐
- conflicting types for ‘方法名’ 的错误
将main()的实现写在drawShapes(),drawCircle(),drawRectangle()...之前. 结果编译的时候出现了 conflicting types for " ...
- 迷你MVVM框架 avalonjs 学习教程13、模板引用
稍为复杂一点的网站都是多个前端工程师合作而成,因此分工是必需的.简单一点的分工就是一个人负责一个频道,某个页面是由一个人全部做的:但如果涉及到一个页面非常复杂,需要多个人同时动工呢?于是到模板的出场时 ...
- 预习 jdbc 技术简介
JDBC简介: JDBC全称为java database connectivity,是sun公司指定的java数据库连接技术的简称. 他是sun公司和数据库开发商共同开发出来的独立于DBMS的应用程序 ...
- chm 文件生成器
1.看云:官网 https://www.kancloud.cn/price 价格如下:
- Spring Boot logback
前言 今天来介绍下spring Boot如何配置日志logback,我刚学习的时候,是带着下面几个问题来查资料的,你呢 如何引入日志? 日志输出格式以及输出方式如何配置? 代码中如何使用? 正文 Sp ...
- thymeleaf 拼接字符串与变量
参考https://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html <span th:text="'The name o ...
- thymeleaf从session中获取数据
<input th:value="${session.value1}" />
- focal
focal 美 ['foʊk(ə)l] 英 ['fəʊk(ə)l] adj.中心的:很重要的:焦点的:有焦点的 网络劲浪:在焦点上的:局部
- virtualbox Linux与Windows共享文件
安装virtualbox增强功能 在Windows下新建文件用于共享,点设置->共享文件夹->添加共享文件,制定路径和名称(名称用于Linux中挂载使用)(选择固定分配) 在Linux中m ...
- codeblocks不支持c++11的有效解决办法
首先cb支持c++11编程开发,但是不支持编译 看了网上好多,说setting里面设置一下就好了,16.01版本我安装了带ide的不带IDE的,安了好多次,但是就是没有那个选项 找不到c++11那个选 ...