题解 | #接水问题#
接水问题
https://ac.nowcoder.com/acm/problem/16600
include
using namespace std;
int n,m,ans=0,k=1,res=0;
const int p=10010;
int q[p];
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>q[i];
}
while(res!=m)
{
ans++;
for(int i=1;i<=m;i++)
{
q[i]--;
if(q[i]==0)
{
if(m+k<=n)
q[i]=q[m+k++];
else
res++;
}
}
}
cout<<ans;
return 0;
}