Cola
Time limit1sMemory limit128 MB
Given final cola levels after N people each drank from the fullest (W) or emptiest nonempty (E) bottle in turn, reconstruct the lexicographically smallest sequence of bottle choices.
- Level
Medium7 of 10
- Topics
- Simulation, Greedy, Heap
- Solved
- No attempts yet
Problem
There are M bottles of a very popular drink called cola in a room. The bottles are numbered 1, 2, ..., M, and no two bottles share a number. Initially every bottle contains exactly K decilitres of cola.
A queue of N thirsty people stands at the door. The people are numbered 1, 2, ..., N. One at a time, in order of their numbers (person 1 first, then person 2, and so on), each person enters the room, drinks exactly one decilitre of cola from a single bottle, and leaves. At most one person is in the room at any moment.
There are two kinds of people. A wasteful person always drinks from one of the currently most-filled bottles. An economical person always drinks from one of the currently least-filled bottles that is not empty (empty bottles are ignored). When several bottles qualify, the person may choose any one of them.
Given how much cola remains in every bottle after the last person leaves, determine, for each person, which bottle they drank from.
Input
The first line contains three integers N, M and K (1 ≤ N ≤ 1000, 1 ≤ M ≤ 100, 1 ≤ K ≤ 20): the number of people in the queue, the number of bottles, and the amount of cola (in decilitres) initially in each bottle.
The second line contains a string of N characters, each either 'W' or 'E'. The i-th character describes person i: 'W' for a wasteful person and 'E' for an economical person.
The third line contains M integers; the j-th integer is the amount of cola remaining in bottle j after everyone has drunk. Each of these integers belongs to the set {0, 1, ..., K}.
Output
Print N integers on one line, separated by single spaces: the i-th integer is the number of the bottle from which person i drank.
At least one assignment consistent with the drinking rules and the final amounts always exists, but it need not be unique. Print the lexicographically smallest valid assignment: compare two assignments by their sequences of bottle numbers starting from person 1, and output the one that is smaller at the first position where the two sequences differ.