Up Down Subsequence
시간 제한: 2000ms메모리 제한: 1024MB출처: USACO 2022 Open PlatinumBOJ 24973
문제
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 .
예제
예제 1
입력
5 1 5 3 4 2 UDUD
출력
4
예제 2
입력
5 1 5 3 4 2 UUDD
출력
3
코드를 제출하려면 로그인하세요.