Time Limit: 1 second

Memory Limit: 32 MB

【问题描述】

高考结束后,同学们大都找到了一份临时工作,渴望挣得一些零用钱。从今天起,Matrix67将连续工作N天(1<=N<=100 000)。每

一天末他可以领取当天及前面若干天里没有领取的工资,但他总共只有M(1<=M<=N)次领取工资的机会。Matrix67已经知道了在接

下来的这N天里每一天他可以赚多少钱。为了避免自己滥用零花钱,他希望知道如何安排领取工资的时间才能使得领到工资最多

的那一次工资数额最小。注意Matrix67必须恰好领工资M次,且需要将所有的工资全部领走(即最后一天末需要领一次工资)。

【输入格式】

第一行输入两个用空格隔开的正整数N和M

以下N行每行一个不超过10000正整数,依次表示每一天的薪水。

【输出格式】

输出领取到的工资的最大值最小是多少。

Sample Input

7 5

100

400

300

100

500

101

400

Sample Output

500

【题目链接】:http://noi.qz5z.com/viewtask.asp?id=t035

【题解】



二分领取的工资为多少;

如果能够在m次内领走就缩小答案;否则增大答案;

裸题;



【完整代码】

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <stack>
#include <string>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second typedef pair<int,int> pii;
typedef pair<LL,LL> pll; void rel(LL &r)
{
r = 0;
char t = getchar();
while (!isdigit(t) && t!='-') t = getchar();
LL sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
} void rei(int &r)
{
r = 0;
char t = getchar();
while (!isdigit(t)&&t!='-') t = getchar();
int sign = 1;
if (t == '-')sign = -1;
while (!isdigit(t)) t = getchar();
while (isdigit(t)) r = r * 10 + t - '0', t = getchar();
r = r*sign;
} const int MAXN = 1e5+100;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0); int n,m;
int a[MAXN]; bool ok(int x)
{
int now = 0,cnt = 1;
rep1(i,1,n)
if (now+a[i]>x)
{
cnt++;
if (cnt>m) return false;
now = a[i];
if (now > x) return false;
}
else
now+=a[i];
return true;
} int main()
{
//freopen("F:\\rush.txt","r",stdin);
scanf("%d%d",&n,&m);
int l = 0,r= 0;
rep1(i,1,n)
rei(a[i]),r+=a[i];
int ans = -1;
while (l <= r)
{
int m = (l+r)>>1;
if (ok(m))
ans = m,r = m-1;
else
l=m+1;
}
printf("%d\n",ans);
return 0;
}

最新文章

  1. 几种简单的负载均衡算法及其Java代码实现
  2. 【Mocha.js 101】Mocha 入门指南
  3. C#----对时间结构DateTime的使用(时间日期的使用)
  4. C语言 homework(4)
  5. oracle创建job权限
  6. Charles是mac的iddler抓包工具
  7. 文本输入框的两种div+css的写法
  8. JAVA面试中的几个重要基础问题
  9. 在Fabric ChainCode中导入第三方包(以状态机为例)
  10. Fiddle手机抓包
  11. 移动端touchstart,touchmove,touchend
  12. ASP.NET Identity 三(转载)
  13. SQL Server 查询数据库中被锁定的表
  14. javascript:原型与原型链
  15. Redis 入门指令
  16. September 26th 2017 Week 39th Tuesday
  17. jQuery中如何解决多库冲突问题
  18. leetcode-55-跳跃游戏
  19. Ansible 小手册系列 六(Patterns 匹配模式)
  20. angularJS---service

热门文章

  1. worktools-git 工具的使用总结(知识点累积)
  2. Filebeat的下载(图文讲解)
  3. 前端上传文件 后端PHP获取文件
  4. SVN和Git代码管理小结
  5. 【2017"百度之星"程序设计大赛 - 复赛】Arithmetic of Bomb
  6. powerdesigner逆向自动生成mysql说明文档、PDM
  7. 洛谷 P2819 图的m着色问题
  8. LayoutAnimation-容器动画
  9. AMBA标准
  10. Android OnGestureListener用法 识别用户手势 左右滑动