萌新最后一个点过了,其他9个点Runtime Error,但是找不出来原因
查看原帖
萌新最后一个点过了,其他9个点Runtime Error,但是找不出来原因
1054475
w_god楼主2023/8/31 12:37
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e7 + 10;
int w[maxn];
int who[maxn] , now[maxn];
 
int main()
{
	int n , m;
	scanf("%d%d" , &n , &m);
	for (int i = 1 ; i <= n ; i++)
	{
		scanf("%d" , &w[i]);
	}
	for (int i = 1 ; i <= m ; i++)
	{
		who[i] = i;
		now[i] = 0;
	}
	int next = m + 1;
	int cnt = 0;
	int ans = -1;
	
	for (int i = 1 ; i <= 1000000 ; i++)
	{
		for (int j = 1 ; j <= m ; j++)
		{
			now[j]++;
			if (now[j] == w[who[j]])
			{
				if (next > n)
				{
					who[j] = -10086;
				}
				else
				{
					who[j] = next;
					next++;
				}
				now[j] = 0;
				cnt++;
			}
		}
		if (cnt == n)
		{
			ans = i;
			break;
		}
	}
	printf("%d" , ans);
	return 0;
}
2023/8/31 12:37
加载中...