Escape from Asgard
InterviewTime limit2sMemory limit1024 MB
Split groups of people between an upper deck with A seats and a lower deck with B seats, and check whether group 1 can sit on the upper deck.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Array
- Solved
- No attempts yet
Statement
Thor and the other residents of Asgard are escaping on the Grandmaster's ship. But first they have to board it.
The ship has two decks. The upper deck has seats and the lower deck has seats. The entrance is on the upper deck. Thor directs the boarding. It is not simple, though. The residents form groups of friends, and each group wants to sit entirely on one deck so they can talk easily. Thor is in group 1. Since Thor directs the boarding, his group boards last, and to avoid delaying the departure, they want to sit on the upper deck.
Determine whether the groups can be split between the two decks so that everyone gets a seat. If so, determine whether the split can also place group 1, Thor's group, on the upper deck.
Input
The first line contains integers , , and : the number of groups, the number of seats on the upper deck, and the number of seats on the lower deck (, ). The next line contains integers , the number of people in each group ().
Output
If the groups cannot be split so that all people get seats, print . Otherwise, if group 1 can be on the upper deck, print ; if not, print . The next two lines describe the upper deck, then the lower deck. Each line starts with the number of groups on that deck, followed by the group numbers. Groups are numbered from 1 in input order.