……睡太晚了。

。。脑子就傻了……

这个题想的时候并没有想到该这样……

题意大概是有n堆箱子从左往右依次排列,每堆ai个箱子,有m个人,最開始都站在第一个箱子的左边,

每个人在每一秒钟都必须做出两种选择中的一种:1若他的位置有箱子则搬走一个箱子,2往右走一步。

问把全部箱子都搞掉的最少时间……

非常显然二分一下答案,若为x秒,则每一个人都有x秒。一个一个排出去搬。看是否可以搬完……

我居然没想到……

#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<climits>
#include<list>
#include<iomanip>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
int a[100010];
bool isok(int n,int m,ll x)
{ll t=x;for(int i=0;i<n;i++){int re=a[i];ll t1=t-i-1;if(t1<0){if(m==0)return 0;t1=x-i-1;t=x;m--;}if(re>0){if(t1>=re)t-=re;else{re-=t1;t1=x-i-1;t=x;int t2=re/t1;re-=t2*t1;if(re>0){t2++;t-=re;}elset=0;m-=t2;if(m<0)return 0;}}}return 1;
}
int main()
{int n,m;cin>>n>>m;for(int i=0;i<n;i++)cin>>a[i];for(int i=n-1;i>-1;i--)if(a[i]!=0){n=i+1;break;}ll l=n+1,r=ll(1e15);while(l<=r){ll md=l+r>>1;if(isok(n,m-1,md))r=md-1;elsel=md+1;}cout<<l;
}
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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:

  1. If i ≠ n, move from pile i to pile i + 1;
  2. 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 test(s)
input
2 1
1 1

output
4

input
3 2
1 0 2

output
5

input
4 100
3 4 5 4

output
5

Note

First sample: Student will first move to the first pile (1 second), then remove box from first pile (1 second), then move to the second pile (1 second) and finally remove the box from second pile (1 second).

Second sample: One of optimal solutions is to send one student to remove a box from the first pile and a box from the third pile, and send another student to remove a box from the third pile. Overall, 5 seconds.

Third sample: With a lot of available students, send three of them to remove boxes from the first pile, four of them to remove boxes from the second pile, five of them to remove boxes from the third pile, and four of them to remove boxes from the fourth pile. Process will be over in 5 seconds, when removing the boxes from the last pile is finished.

转载于:https://www.cnblogs.com/gccbuaa/p/7372936.html

codeforces 551 C GukiZ hates Boxes相关推荐

  1. CodeForces - 551C GukiZ hates Boxes(二分+贪心)

    题目链接:点击查看 题目大意:给出一个长度为 n 的数列 a,表示每个位置的障碍物数量,现在有 m 个学生可以来搬走障碍物,每一秒钟可以做出的行为如下: 从位置 i 移动到位置 i + 1 从当前位置 ...

  2. 【codeforces 768F】 Barrels and boxes

    http://codeforces.com/problemset/problem/768/F (题目链接) 题意 A,B两种物品可以装到栈中,每个栈只能存放一种物品,容量没有限制.现在讲所有栈排成一列 ...

  3. 【CodeForces - 260C】Balls and Boxes (思维模拟,有坑,时光倒流)

    题干: Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with ...

  4. CodeForces 985 E Pencils and Boxes

    Pencils and Boxes 题意: n支铅笔,每只笔有一个颜色值, 无限个盒子, 如果一个盒子里面放笔的话, 就至少需要k支笔装在一起,并且一个盒子里面的笔的颜色值只差 不能大于 d.如果满足 ...

  5. codeforces contest 985E. Pencils and Boxes+思维

    类似指针的想法 E. Pencils and Boxes time limit per test 2 seconds memory limit per test 256 megabytes input ...

  6. Codeforces 985 E - Pencils and Boxes

    E - Pencils and Boxes 思路: dp 先排个序,放进一个袋子里的显然是一段区间 定义状态:pos[i]表示小于等于i的可以作为(放进一个袋子里的)一段区间起点的离i最近的位置 显然 ...

  7. c语言函数指针封装函数,C语言之函数指针、回调函数的使用

    一.背景 首先看下如下代码,这个定义是放在头文件的,在程序中tCdrvCallbackFkt也定义了另一个变量,而且括号后面还跟定义了几个变量,不理解这个定义. typedef void (PUBLI ...

  8. python的网页解析器_Beautiful Soup常见的解析器

    window系统下,简单的FTP上传和下载操作 先假设有一FTP服务器,FTP服务器:qint.ithot.net,用户名:username   密码:user1234.在本地电脑D:盘创建一个文件夹 ...

  9. 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/ ...

最新文章

  1. ADuC845串口下载模块制作
  2. java例程练习(批量修改文件后缀名)
  3. mikadonic-iptables学习笔记
  4. Java 8中的功能接口是什么? @功能注释和示例
  5. Python 中 异步协程 的 使用方法介绍
  6. CSS3实现小黄人动画
  7. Linux下使用ntpdate进行时间同步
  8. python入门-简单的文件备份程序
  9. websocket实现java服务端与js端通信
  10. 开热点给电脑消耗大吗_你试过爬楼梯减肥吗?热量消耗大,选对姿势很重要!...
  11. 04 Mysql之单表查询
  12. 虚拟机VMware tools安装
  13. 【一天一算法】冒泡排序
  14. OD查找QQ sessionkey教程
  15. 医院排队系统排队叫号系统
  16. 总线及单片机各种线 以及数据总线宽度
  17. 人生十个阶段,每七年周期变化
  18. 车联网TBOX国六OBD排放终端远程在线监控系统
  19. cocoscreator中tween详细用法
  20. 论文笔记 Digging into self-supervised monocular depth estimation

热门文章

  1. [javaSE] 多线程(join方法)
  2. Keepalived+HAProxy基于读写分离方式实现discuz论坛
  3. createSQLQuery的addEntity跟setResultTransformer方法
  4. 刚发现的,免费领取1024G云空间
  5. select元素的options.add 与 insertbefore的区别
  6. JAVA基础知识(5)
  7. key to ribbon chart in powerbi: time, category, value
  8. 哥伦比亚大学计算机工程面试题
  9. Mac系统安装和配置tomcat步骤详解
  10. GridView导出到Excel或Word文件