L2-4 彩虹瓶 (25 分)
#include <iostream>
#include<stack>
using namespace std;
int main()
{
int N,M,K;
cin>>N>>M>>K;
int p[1000];
int i;
for(i=0;i<K;i++)
{
stack<int> s1,s2;
bool over=false;
for(int j=0;j<N;j++)
cin>>p[j];
s1.push(0);
for(int j=0;j<N;j++)
{
if(!s2.empty()&&s2.top()==s1.top()+1&&s2.size()<=M)
{
s1.push(s2.top());
s2.pop();
j--;
continue;
}
if(p[j]==s1.top()+1)
{
s1.push(p[j]);
}
else
{
s2.push(p[j]);
}
if(s2.size()>M)
{
over=true;
cout<<"NO"<<endl;
break;
}
}
if(!over)
while(!s2.empty())
{
if(s2.top()==s1.top()+1)
{
s1.push(s2.top());
s2.pop();
}
else
{
cout<<"NO"<<endl;
break;
}
}
if(s2.empty())
cout<<"YES"<<endl;
}
return 0;
}