求助
查看原帖
求助
632830
Mark_666楼主2024/7/30 16:46
#include<bits/stdc++.h>
using namespace std;
const int N=1e4+10;
int n,m;
int a[N];
int t[N];
stack<int> st;
//queue<int> q;
int cnt;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	cnt=m;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=n;i>=1;i--)
		st.push(a[i]);
	for(int i=1;;i++)
	{
		for(int j=1;j<=m;j++){
			if(!st.empty()){
				t[j]=st.top()-1;
				st.pop();
			}
			else cnt=j;
		}
		for(int j=1;j<=cnt;j++)
			if(t[j]>0) st.push(t[j]);
		if(st.empty())
		{
			cout<<i;
			return 0;
		}
	}
	return 0;
}

20分,其他点都TLE了

2024/7/30 16:46
加载中...