显示代码纯文本
#include <iostream>
#include <cstdio>
using namespace std;
int main(void)
{
freopen("waterj.in","r",stdin);
freopen("waterj.out","w",stdout);
int i,n,m,c,c2,tim=0,first,w[10010],nexw[10010],befw[10010];
cin>>n>>m;
for (i=1;i<=n;i++)
{
cin>>w[i];
nexw[i]=i+1;
befw[i]=i-1;
}
first=1;
c=n;
while (c)
{
tim++;
c2=m;
for (i=first;c>0&&c2>0&&i<=n;i=nexw[i])
{
c2--;
w[i]--;
if (w[i]==0)
{
c--;
if (befw[i]==0)
first=nexw[i];
nexw[befw[i]]=nexw[i];
befw[nexw[i]]=befw[i];
}
}
}
cout<<tim<<endl;
return(0);
}