CF737F Dirty plates
题目描述
你有三个栈$s1,s2,s3$,其中栈$s1$中有$N$个数。现在你有两种操作:
1、将$s1$中栈顶的$c$个元素压入$s2$中,在$s2$中的顺序与在$s1$中的顺序相同,需要满足$1 \leq c \leq a$。
2、将$s2$中栈顶的$c$个元素压入$s3$中,在$s3$中的顺序与在$s2$中的顺序相同,需要满足$1 \leq c \leq b$。
现在,给定$N,a,b$与$s1$中元素的初始顺序,问是否存在一种方案,使得使用上面两种操作之后,所有元素都在$s3$中且$s3$从栈底到栈顶为一个单调递减的序列。你给出的方案不一定要是最优的。
输入格式
第一行三个正整数$N,a,b(1 \leq N \leq 2000 , 1 \leq a , b \leq N)$,意义如题目所述
接下来一行$N$个正整数$s_i$,从栈顶到栈底描述栈中一个元素的值。保证序列$\{s_i\}$为一个长度为$N$的排列。
输出格式
如果存在一种方案,第一行输出$Yes$,接下来一行一个正整数$K$表示你给出的方案中的操作次数,接下来$K$行每行两个整数$t,c$,若$t=1$,表示将$s1$中栈顶的$c$个元素压入$s2$中,若$t=2$表示将$s2$中栈顶的$c$个元素压入$s3$中。如果没有方案满足条件,只需输出一行$No$。
说明/提示
In the first example the initial order of plates was $ 2,3,6,4,1,5 $ . Here is how the stacks look like after each of the operations:
- \[1 2\]: Dirty stack: $ 6,4,1,5 $ . Intermediary stack: $ 2,3 $ . The dryer is empty.
- \[1 1\]: Dirty stack: $ 4,1,5 $ . Intermediary stack: $ 6,2,3 $ . The dryer is empty.
- \[2 1\]: Dirty stack: $ 4,1,5 $ . Intermediary stack: $ 2,3 $ . Dryer stack: $ 6 $ .
- \[1 2\]: Dirty stack: $ 5 $ . Intermediary stack: $ 4,1,2,3 $ . Dryer stack: $ 6 $ .
- \[1 1\]: There are no dirty plates. Intermediary stack: $ 5,4,1,2,3 $ . Dryer stack: $ 6 $ .
- \[2 1\]: There are no dirty plates. Intermediary stack: $ 4,1,2,3 $ . Dryer stack: $ 5,6 $ .
- \[2 1\]: There are no dirty plates. Intermediary stack: $ 1,2,3 $ . Dryer stack: $ 4,5,6 $ .
- \[2 3\]: All the plates are in the dryer: $ 1,2,3,4,5,6 $ .
In the second example it is possible to wash all the plates in one operation, and then move them all to the dryer.This is not possible in the third example, because it is not permitted to move more than one plate at the same time. It is possible to wash plates one by one so that they are placed onto the intermediary stack in the reverse order, and then move plates one by one to the dryer. The final order is correct.