C. GukiZ hates Boxes

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/551/problem/C

Description

Professor GukiZ is concerned about making his way to school, because massive piles of boxes are blocking his way.

In total there are n piles of boxes, arranged in a line, from left to right, i-th pile (1 ≤ i ≤ n) containing ai boxes. Luckily, m students are willing to help GukiZ by removing all the boxes from his way. Students are working simultaneously. At time 0, all students are located left of the first pile. It takes one second for every student to move from this position to the first pile, and after that, every student must start performing sequence of two possible operations, each taking one second to complete. Possible operations are:

If i ≠ n, move from pile i to pile i + 1;
    If pile located at the position of student is not empty, remove one box from it.

GukiZ's students aren't smart at all, so they need you to tell them how to remove boxes before professor comes (he is very impatient man, and doesn't want to wait). They ask you to calculate minumum time t in seconds for which they can remove all the boxes from GukiZ's way. Note that students can be positioned in any manner after t seconds, but all the boxes must be removed.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 105), the number of piles of boxes and the number of GukiZ's students.

The second line contains n integers a1, a2, ... an (0 ≤ ai ≤ 109) where ai represents the number of boxes on i-th pile. It's guaranteed that at least one pile of is non-empty.

Output

In a single line, print one number, minimum time needed to remove all the boxes in seconds.

Sample Input

2 1
1 1

Sample Output

4

HINT

题意

有一群小学生帮着老师搬东西,一开始小学生都在0点,然后每次每个小学生有两种操作,1是移动一格,2是搬走一堆东西

然后问你花费最少的时间

题解:

想dp的都是傻逼(没错就是我!

直接二分答案之后,然后贪心就好了……

代码:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 2000001
#define mod 10007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** ll a[maxn],b[maxn];
int n,m;
bool check(ll x)
{
for(int i=;i<=n;i++)
b[i]=a[i];
ll tmp=;
int cur=n;
for(int i=;i<=m;i++)
{
while(cur>=&&b[cur]==)
cur--;
if(cur==)
return ;
tmp=cur;
if(tmp>x)
continue;
while(cur>=&&b[cur]+tmp<=x)
{
tmp+=b[cur];
b[cur]=;
cur--;
}
if(cur==)
return ;
b[cur]-=(x-tmp);
}
return ;
}
int main()
{
//test;
ll sum=;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
scanf("%lld",&a[i]);
sum+=a[i];
}
sum+=n;
ll L=,R=sum;
while(L<R)
{
ll M=(L+R)>>;
if(check(M))
R=M;
else
L=M+;
}
printf("%lld\n",R);
return ;
}

Codeforces Round #307 (Div. 2) C. GukiZ hates Boxes 贪心/二分的更多相关文章

  1. Codeforces Round #307 (Div. 2) C. GukiZ hates Boxes 二分

    C. GukiZ hates Boxes time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  2. 水题 Codeforces Round #307 (Div. 2) A. GukiZ and Contest

    题目传送门 /* 水题:开个结构体,rk记录排名,相同的值有相同的排名 */ #include <cstdio> #include <cstring> #include < ...

  3. Codeforces Round #307 (Div. 2) E. GukiZ and GukiZiana 分块

    E. GukiZ and GukiZiana Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55 ...

  4. Codeforces Round #307 (Div. 2) A. GukiZ and Contest 水题

    A. GukiZ and Contest Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/ ...

  5. Codeforces Round #307 (Div. 2) D. GukiZ and Binary Operations 矩阵快速幂优化dp

    D. GukiZ and Binary Operations time limit per test 1 second memory limit per test 256 megabytes inpu ...

  6. Codeforces Round #307 (Div. 2) E. GukiZ and GukiZiana(分块)

    E. GukiZ and GukiZiana time limit per test 10 seconds memory limit per test 256 megabytes input stan ...

  7. Codeforces Round #307 (Div. 2) D. GukiZ and Binary Operations (矩阵高速幂)

    题目地址:http://codeforces.com/contest/551/problem/D 分析下公式能够知道,相当于每一位上放0或者1使得最后成为0或者1.假设最后是0的话,那么全部相邻位一定 ...

  8. Codeforces Round #307 (Div. 2) E. GukiZ and GukiZiana (分块)

    题目地址:http://codeforces.com/contest/551/problem/E 将n平均分成sqrt(n)块,对每一块从小到大排序,并设置一个总体偏移量. 改动操作:l~r区间内,对 ...

  9. Codeforces Round #307 (Div. 2) D. GukiZ and Binary Operations

    得到k二进制后,对每一位可取得的方法进行相乘即可,k的二进制形式每一位又分为2种0,1,0时,a数组必定要为一长为n的01串,且串中不出现连续的11,1时与前述情况是相反的. 且0时其方法总数为f(n ...

随机推荐

  1. Linux下安装loadrunner步骤及遇到的问题

    Linux下实现压力测试,只能在Linux下安装加压器---load-generator,然后通过本地录制脚本,通过loadrunner controller 的Scenario-->Load ...

  2. LR之配置端口映射(port mapping)

    1.那些协议需要配置 tools-recording_options-network-port mapping 2.定义端口映射 3.自动检测原理 4.特殊情况

  3. centos7虚拟机无法上网的解决办法

    今天在VMware虚拟机中经过千辛万苦终于安装好了centos7..正兴致勃勃的例行yum update 却发现centos系统貌似默认网卡没配置好,反馈无法联网.经过一番研究,终于让centos连上 ...

  4. js正则表达式中=s.g表示什么意思

    //g是全局匹配//中间的内容表示:匹配以=开关,后面是0或多个空格,然后是双引号括起来的任意字符,比如:= "any symble" 匹配 = " asfjaskldf ...

  5. OPENGL学习笔记整理(五):着色语言

    有些事情本身就是十分奇怪的.在传统上,图形硬件的设计目的是用于快速执行相同的硬编译指令集.不同的计算步骤可以被跳过,参数可以被调整,但计算本身确实固定不变的.然而,随着技术的发展,却越来越变得可以编程 ...

  6. 关于Activity的少许细节

    1.  对活动应用样式和主题 2.  隐藏活动标题 3. 显示对话框窗口 4. 显示进度对话框 1.  应用样式和主题 改成 android:theme="@android:style/Th ...

  7. md5加密算法c语言版

    from: http://blog.sina.com.cn/s/blog_693de6100101kcu6.html 注:以下是md5加密算法c语言版(16/32位) ---------------- ...

  8. log4net--帮助程序员将日志信息输出到各种目标(控制台、文件、数据库等)的工具

    1. log4net库是Apache log4j框架在Microsoft .NET平台的实现,是一个帮助程序员将日志信息输出到各种目标(控制台.文件.数据库等)的工具. 2. Log4net的结构如下 ...

  9. VCS之Git

    Git -- open source distributed version control system -- A stream of snapshots(if no change,just lin ...

  10. STL源码分析读书笔记--第二章--空间配置器(allocator)

    声明:侯捷先生的STL源码剖析第二章个人感觉讲得蛮乱的,而且跟第三章有关,建议看完第三章再看第二章,网上有人上传了一篇读书笔记,觉得这个读书笔记的内容和编排还不错,我的这篇总结基本就延续了该读书笔记的 ...