Up Down Subsequence
시간 제한2초메모리 제한1024 MB
순열과 U/D 문자열이 주어질 때, 앞에서부터 K개의 부등호를 만족하는 부분수열의 최대 길이를 구한다.
문제
Farmer John's cows (), conveniently numbered as usual, have ordered themselves according to a permutation of . You are also given a string of length consisting of the letters U and D. Please find the maximum such that there exists a subsequence of such that for all , if the th letter in the string is U, and if the th letter in the string is D.
입력
The first line contains .
The second line contains .
The last line contains the string.
출력
Write out maximum possible value of .