50分,TLE了,求助
查看原帖
50分,TLE了,求助
738168
wang0728楼主2023/7/27 16:29
#include <bits/stdc++.h>
using namespace std;
int n,m,w[10005],l,r,sum[10005],ans,s;
bool flag[105],t[10005];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>w[i];
	l=1,r=m;
	for(int i=1;;i++){
		for(int j=l;j<=r&&j<=n;j++){
			if(flag[j]==false&&t[j]!=true) sum[j]++;
			t[j]=false;
			if(sum[j]==w[j]&&flag[j]==false){
				r++;s++;
				t[r]=true;
				if(r>=n) r=n;
				flag[j]=true;
			}
		}
		ans++;
		if(s==n) break;
	}
	cout<<ans;
	return 0;
}
2023/7/27 16:29
加载中...