Target Practice
시간 제한2초메모리 제한1024 MB
로봇이 수직선 위에서 L, R, F 명령 문자열을 따라 움직이며 정해진 위치의 목표물을 맞힌다. 명령을 최대 하나 바꿔 맞힐 수 있는 목표물 수의 최댓값을 구한다. 위치와 목표물 번호에 대한 접두사 동적 계획법으로 푼다.
문제
Bessie is a robovine, also known as a cowborg. She is on a number line trying to shoot a series of targets located at distinct positions. Bessie starts at position and follows a string of commands, each one of L, F, or R:
- L: Bessie moves one unit to the left.
- R: Bessie moves one unit to the right.
- F: Bessie fires. If there is a target at Bessie's current position, it is hit and destroyed, and cannot be hit again.
If you are allowed to change up to one command in the string to a different command before Bessie starts following it, what is the maximum number of targets that Bessie can hit?
입력
The first line contains and .
The next line contains the locations of the targets, distinct integers in the range .
The next line contains the command string of length , containing only the characters F, L, and R.
출력
Print the maximum number of targets that Bessie can hit after changing up to one command in the string.