题目传送门:https://pintia.cn/problem-sets/994805046380707840/problems/1111914599412858889
题解:
//本题主要是栈的应用 #include<stack> #include<iostream> using namespace std; int main() { int N, M, K, temp; cin >> N >> M >> K; stack<int>s1; while (K--) { while (!s1.empty()) { s1.pop(); } int f = 1; bool flag = false; for (int i = 0; i < N; i++) { cin >> temp; if (temp == f) { f++; while (!s1.empty()&& s1.top() == f) { s1.pop(); f++; } } else { s1.push(temp); if (s1.size() > M) { flag = true; } } } if (flag||!s1.empty()) { cout << "NO" << endl; } else { cout << "YES" << endl; } } return 0; }