……睡太晚了。

。。脑子就傻了……

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

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

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

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

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

我居然没想到……

  1. #include<map>
  2. #include<string>
  3. #include<cstring>
  4. #include<cstdio>
  5. #include<cstdlib>
  6. #include<cmath>
  7. #include<queue>
  8. #include<vector>
  9. #include<iostream>
  10. #include<algorithm>
  11. #include<bitset>
  12. #include<climits>
  13. #include<list>
  14. #include<iomanip>
  15. #include<stack>
  16. #include<set>
  17. using namespace std;
  18. typedef long long ll;
  19. int a[100010];
  20. bool isok(int n,int m,ll x)
  21. {
  22. ll t=x;
  23. for(int i=0;i<n;i++)
  24. {
  25. int re=a[i];
  26. ll t1=t-i-1;
  27. if(t1<0)
  28. {
  29. if(m==0)
  30. return 0;
  31. t1=x-i-1;
  32. t=x;
  33. m--;
  34. }
  35. if(re>0)
  36. {
  37. if(t1>=re)
  38. t-=re;
  39. else
  40. {
  41. re-=t1;
  42. t1=x-i-1;
  43. t=x;
  44. int t2=re/t1;
  45. re-=t2*t1;
  46. if(re>0)
  47. {
  48. t2++;
  49. t-=re;
  50. }
  51. else
  52. t=0;
  53. m-=t2;
  54. if(m<0)
  55. return 0;
  56. }
  57. }
  58. }
  59. return 1;
  60. }
  61. int main()
  62. {
  63. int n,m;
  64. cin>>n>>m;
  65. for(int i=0;i<n;i++)
  66. cin>>a[i];
  67. for(int i=n-1;i>-1;i--)
  68. if(a[i]!=0)
  69. {
  70. n=i+1;
  71. break;
  72. }
  73. ll l=n+1,r=ll(1e15);
  74. while(l<=r)
  75. {
  76. ll md=l+r>>1;
  77. if(isok(n,m-1,md))
  78. r=md-1;
  79. else
  80. l=md+1;
  81. }
  82. cout<<l;
  83. }

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
  1. 2 1
  2. 1 1
output
  1. 4
input
  1. 3 2
  2. 1 0 2
output
  1. 5
input
  1. 4 100
  2. 3 4 5 4
output
  1. 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.


codeforces 551 C GukiZ hates Boxes的更多相关文章

  1. 【24.67%】【codeforces 551C】 GukiZ hates Boxes

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. Codeforces Round #307 (Div. 2) C. GukiZ hates Boxes 贪心/二分

    C. GukiZ hates Boxes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/ ...

  3. Codeforces 551C GukiZ hates Boxes(二分)

    Problem C. GukiZ hates Boxes Solution: 假设最后一个非零的位置为K,所有位置上的和为S 那么答案的范围在[K+1,K+S]. 二分这个答案ans,然后对每个人尽量 ...

  4. 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 ...

  5. Codeforces 551 D. GukiZ and Binary Operations

    \(>Codeforces \space 551 D. GukiZ and Binary Operations<\) 题目大意 :给出 \(n, \ k\) 求有多少个长度为 \(n\) ...

  6. CodeForces 551C - GukiZ hates Boxes - [二分+贪心]

    题目链接:http://codeforces.com/problemset/problem/551/C time limit per test 2 seconds memory limit per t ...

  7. Codeforces 551C GukiZ hates Boxes 二分答案

    题目链接 题意:  一共同拥有n个空地(是一个数轴,从x=1 到 x=n),每一个空地上有a[i]块石头  有m个学生  目标是删除全部石头  一開始全部学生都站在 x=0的地方  每秒钟每一个学生都 ...

  8. 二分+贪心 || CodeForces 551C GukiZ hates Boxes

    N堆石头排成一列,每堆有Ai个石子.有M个学生来将所有石头搬走.一开始所有学生都在原点, 每秒钟每个学生都可以在原地搬走一块石头,或者向前移动一格距离,求搬走所有石头的最短时间. *解法:二分答案x( ...

  9. CF GukiZ hates Boxes 【二分+贪心】

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

随机推荐

  1. 网速4M等于多少KB/S,等于多少kbps

    4M=512KB/S=4096Kbps 1KB/S=8Kbps 8倍速 转:http://zhidao.baidu.com/link?url=8GAyhcY9BbVstQr8pE3I7QP_M53Km ...

  2. [Winform]无边框窗口悬浮右下角并可以拖拽移动

    摘要 简单实现了一个这样的功能,程序启动时,窗口悬固定在右下角,并可以通过鼠标拖拽移动. 核心代码块 无边框窗口并不出现在任务栏 //无边框 this.FormBorderStyle = System ...

  3. AutoMapper在MVC中的运用小结

    配置.单元测试.AOP注入 Decimal转换成String类型 源数组转换成目标数组 源中的集合(数组)属性转换成目标中的集合(数组)属性 子类父类间的映射 源字典集合转换成目标字典集合 枚举映射 ...

  4. ios7下UISearchBar UITextField 光标不出现的问题

    app支持ios7,在UINavBar 里面加入搜索框,结果光标一直出现不了.在overstackflow网站搜索了一下,竟然有人遇到相同的问题.... 解决办法如下: searchBar.tintC ...

  5. C#输出到Release VS中Release模式下生成去掉生成pdb文件

    Release 与 Debug 的区别就不多说了, 简单来说 Release 优化过, 性能高一些. Debug 为方便调试. 默认情况下是 Debug, 那如何改成 Release 呢? 项目上右键 ...

  6. [wxWidgets]_[0基础]_[不常见但有用的类wxStandardPaths]

    场景: 1.wxStandardPaths   用来获取各种系统路径.能够用于存放app的配置数据.比方文档文件夹,appData等. 代码: #include "wx/wxprec.h&q ...

  7. pip 安装错误 'ascii' codec can't encode characters

    安装 python-dev既可解决 apt-get install python-dev

  8. Material Designer的低版本兼容实现(七)—— Rectange Button

    矩形按钮是我们很常用的控件,让其拥有5.0动效必须自定义控件.本文讲解的控件是参考: https://github.com/shark0017/MaterialDesignLibrary 一.放入布局 ...

  9. B. Random Teams(Codeforces Round 273)

    B. Random Teams time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  10. [leetcode]Rotate Image @ Python

    原题地址:https://oj.leetcode.com/problems/rotate-image/ 题意: You are given an n x n 2D matrix representin ...