有没有在刷pta甲级或者懂数据结构(特别是堆栈)的小伙伴来帮忙看看

Pop Sequence (25 分)这道题过不去,报段错误,可是我调试一遍没问题啊,上代码让大家看看哪里出错了

#include<iostream>
#include<stack>
using namespace std;
int main() {
	int M = 0, N = 0, K = 0;
	cin >> M >> N >> K;
	int num = 0, max = 0, count = 0;
	int arr[1001] = {0};
	for (int i = 0; i < K; i++)
	{
		stack<int> s;
		for (int j = 1; j <= N; j++)//将出栈顺序存入数组
		{
			cin >> num;
			arr[j] = num;
			if (arr[j-1]<num)  //有入栈
			{
				for (int k = max + 1; k <= num; k++) 
					s.push(k);
				
				if (s.size()>M) //如果入栈的元素大于栈的容量
					break;
				else
					++count;
				s.pop();
				if (num>max)  //求max
					max = num;
			}
			else //没有入栈只有出栈
			{
				if (num!=s.top())			
					break;
				else {
					++count;
					s.pop();
				}		
			}
		}
		if (count == N)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
		max = 0;
		count = 0;
	}
	}