玄关
#include <bits/stdc++.h>
using namespace std;
int a[10000];
int l[10000];
bool check(int n)
{
for (int i = 0; i < n; i++)
if (l[i] != a[i]) return false;
return true;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, res = 0, temp = 0;
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> a[i];
while (!check(n))
{
temp = 0;
for (int i = 0; i < n; i++)
{
if (a[i] == l[i])
{
continue;
}
if (temp++ == m) break;
l[i] += 1;
}
res += 1;
}
cout << res << endl;
return 0;
}
提交地址