Naming the Competition
Time limit2sMemory limit1024 MB
For each interval of cards, compare the best alternating 연고 and 고연 subsequence scores of Y and K, then print the winner and its score.
- Level
Medium7 of 10
- Topics
- Segment tree, Dynamic programming, String
- Solved
- No attempts yet
문제
Yonsei University and Korea University hold an annual rivalry match, and a rule decides its official name. The host school is placed last. When Yonsei hosts, the official name is "Goyeonjeon". When Korea University hosts, it is "Yeongojeon". Regardless of the rule, Yonsei students usually call it "Yeongojeon" and Korea University students call it "Goyeonjeon". When the staff of each school discussed the official name of this competition, each wanted their own school name first. They decided to settle it with the following game. Y, the problem setter from Yonsei, played against K, the problem setter from Korea University.
There are cards in a row. Each card has either '연' or '고' written on it, along with a natural number at most . Number the cards from the left as card 1, card 2, ..., card . From the cards between and inclusive, pick some cards in order. Y picks cards so that the pattern "연고" repeats, and K picks cards so that the pattern "고연" repeats. Two consecutively picked cards cannot have the same letter. Y's first card has '연' and its last card has '고'. K's first card has '고' and its last card has '연'. The sum of the numbers on the cards each player picks is that player's score, and the higher score wins. If a player cannot pick any cards, that player's score is 0.
This game is played times. In each game, Y and K are allowed to pick the same card. Y and K play each game with their school pride at stake, using their best strategy. For each game, print the winner and the winner's score.
입력
The first line contains the number of cards .
The second line contains the letters on the cards as a single string. A card with '연' is written as Y, and a card with '고' is written as K.
The third line contains the natural numbers on each card, separated by spaces. ()
The fourth line contains the number of games .
From the fifth line onward, the lines each contain an interval from which cards may be picked. ()
출력
For each game, print the winner and the winner's score, separated by a space. If the game is a tie, print YK and the score, separated by a space.
제한
힌트
The official name of this competition is "2023 Korea University x Yonsei University Programming Contest".