Calendars
InterviewTime limit1sMemory limit512 MB
Convert each given date to its day of year with one calendar, then locate the matching month and day in the other calendar.
- Level
Medium4 of 10
- Topics
- Prefix sum, Binary search
- Solved
- No attempts yet
Problem
You manage trade between two tribes, the Arbuzans and the Bananits. The trouble is that the two tribes use different calendars.
The Arbuzan calendar has months whose lengths, in days, are . The Bananit calendar has months whose lengths are .
A year has the same number of days in both calendars, that is .
Write a program that converts dates between the Arbuzan and the Bananit calendars.
Input
The first line contains two integers and (), separated by a single space, the number of months in the Arbuzan and the Bananit calendars.
The second line contains the integers (), separated by single spaces, the lengths of the consecutive months of the Arbuzan calendar. The third line contains the integers (), separated by single spaces, the lengths of the consecutive months of the Bananit calendar.
The fourth line contains a single integer (), the number of queries.
Each of the next lines describes one query. It consists of two integers and and one character , separated by single spaces, giving the day, the month, and the direction of conversion. If is the letter A, then and , and the pair denotes a date in the Arbuzan calendar that your program must convert to the Bananit calendar. If is the letter B, then and , and the pair denotes a date in the Bananit calendar that your program must convert to the Arbuzan calendar.
Output
Print lines. The -th line must contain the answer to the -th query as two integers and separated by a single space, where is the day and is the month of the converted date in the target calendar.