Codeforces 551 C Gukiz hates Boxes

Source: Internet
Author: User

...... It's too late to sleep ... The brain is silly ...

I didn't think of it that way.

Test instructions probably have n piles of boxes from left to right in order, each pile of AI boxes, there are m individuals, the first to stand on the left side of the box,

Each person must make one of two choices in every second: 1 if he has a box in his position, move a box and 2 take one step to the right.

Ask for the least amount of time to get rid of all the boxes ...


Obviously two points to the answer, if x seconds, then everyone has x seconds, a row out to move, see if you can move out ...


I didn't think ...

#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 test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Professor Gukiz is concerned on making his and school, because massive piles of boxes was blocking his.

In total there isNPiles of boxes, arranged in a line, from left to right,I-th Pile (1?≤? i? ≤? N ) containing ai Boxes. Luckily,mStudents is willing to help Gukiz by removing all the boxes from his. Students is working simultaneously. At time0, all students is 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 STA RT performing sequence of the possible operations, each taking one second to complete. Possible Operations is:

      if  i ? ≠? n , move from Pile  i  to pile  i ? +?1 ;

Gukiz ' s students aren ' t smart at all, so they need what do I do them how to remove boxes before professor comes (he's 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 of the boxes from Gukiz ' s. Note that students can is positioned in any manner after T seconds, but all the boxes must is removed.

Input

The first line contains integers n and m (1?≤? N,? M.≤?105), the number of piles of boxes and the number of Gukiz ' s students.

The second line containsNIntegers a1,? a 2,?... a N (0?≤? a i? ≤?109 ) where ai Represents the number of boxes onI-th Pile. It's guaranteed in 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 11 1
Output
4
Input
3 21 0 2
Output
5
Input
4 1003 4) 5 4
Output
5
Note

Fir St Sample:student would 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).

Sec Ond sample:one of optimal solutions is-send one student to remove a box from the first pile and a box from the third P Ile, 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 the them to re Move boxes from the second pile, five of them-remove boxes from the third pile, and four of the them to remove boxes from t He fourth pile. Process would be-over- 5 seconds when removing the boxes from the last pile was finished.



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Codeforces 551 C Gukiz hates Boxes

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.