```c
#include <iostream>
using namespace std;
const int N = 10010;
int n , m;
int a[N];
int main()
{
cin >> n >> m;
for(int i = 1; i <= n; i ++) cin >> a[i];
int t = m + 1;
int res = 0;
while(t <= n + m)
{
for(int i = 1; i <= m; i ++)
{
a[i] --;
if(a[i] == 0)
{
a[i] = a[t];
t ++;
}
}
res ++;
}
cout << res << endl;
return 0;
}
```
by 123huchenghao @ 2024-06-28 14:25:05
```c
#include<bits/stdc++.h>
using namespace std;
int sb[1000001];
int now[1000001];
int main(){
int n,m,pos,tot=0;
cin>>n>>m;
pos=m+1;
for(int i=1;i<=n;i++) cin>>sb[i];
while(pos<=n+m) {
for(int i=1;i<=m;i++){
++now[i];
if (now[i]==sb[i]){
now[i]=0;
sb[i]=sb[pos];
pos++;
}
}
tot++;
}
cout<<tot;
}
```
by lhy2022 @ 2024-08-09 17:01:39