Test instructions
Is that n students help the Professor carry the box, the box into the M-heap, each student can choose two operations per second
Operation 1, for from I heap to the i+1 heap,
Operation 2, from the I-1 heap box to help hold a box
Ask for the minimum amount of time to hold all the boxes, and each student can act at the same time every second.
Exercises
Two minutes and then the current time, a police station some students, so that he can walk to the farthest distance
Code:
#include <stdio.h>
int flag, value[100005], value2[100005], N, m;
void find (Long long int mid)
{
Long Long int temp = MID, Fla = 0;
Temp--;
if (flag = = N) return;
if (temp = = 0) return;
while (1)
{
while (!value2[flag])
{
Flag + +;
IF (FLA) temp--;
if (flag = = N) return;
if (temp = = 0) continue;
}
if (!FLA) temp-= flag;
FLA = 1;
if (Value2[flag] <= temp)
{
Temp-= Value2[flag];
Value2[flag] = 0;
if (flag = = n-1) flag + +;
if (flag = = N) return;
if (temp = = 0) continue;
Flag + +, temp--;
if (flag = = N) return;
if (temp = = 0) continue;
}
Else
{
Value2[flag]-= temp;
Return
}
}
}
BOOL Slove (long long int mid)
{
for (int i = 0; i < n; i++)
Value2[i] = Value[i];
Flag = 0;
for (int i = 1; I <= m; i++)
{
Find (mid);
if (flag = = n) break;
}
if (flag = = N) return 1;
return 0;
}
int main ()
{
while (scanf ("%d%d", &n, &m)! = EOF)
{
A long long int sum = 0;
for (int i = 0; i < n; i++)
scanf ("%d", &value[i]), sum + = value[i];
sum + = n;
Long long int l = 0, R = Sum, Mid, Ans =-1;
while (L <= R)
{
Mid = (r+l)/2;
if (Slove (mid))
{
R = mid-1;
Ans = mid;
}
else L = mid + 1;
}
printf ("%lld\n", Ans);
}
}
Codeforces 551c-gukiz hates Boxes (two points and greedy)