HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Sections > Unsorted > problem:


50285 - Meat store

Guest
• Discussion of problem (1)

Section problems

• 50257 - Galls village
• 50266 - Kovrov
• 50254 - Lawyers Council
• 50260 - What about judges?
• 50259 - Many-coloured roads
• 50278 - ATM
• 50277 - Unusual Lottery
• 50283 - Tetris 3D
• 50285 - Meat store
• 50279 - Bit Decoder
• 50284 - Knights of the Rook
• 50282 - Coins
• 50281 - Primes
• 50287 - Providers
• 51004 - Word Search Game
• 50430 - ATM
• 50489 - Football Championship

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
Автор: Дмитрий Шевченко, ВлГУ.

A brand new equipment has been installed in meat store recently - the electronic seller. Now the customer can simply come and press the button, and the seller will select the meat piece automatically. The pieces are stored in a special container inside the seller. Different pieces have different weights (all weights are distinct). There are N pieces of meat in the container. The seller works the following way. There is a special register X in seller circuit, with initial value set to 0. In order to satisfy the customer the seller does the following:
  • All pieces are numbered from 0 to N-1 in order of weight increase.
  • The piece with number equal to register X value is selected.
  • The seller retrieves the selected piece from the container and hands it to the customer.
  • A request for a new piece is sent to a special warehouse. There are M pieces of meat at the warehouse initially (all weights are distinct). When a request comes, a piece with maximal weight is selected and sent to the container. Thus, the total number of pieces in container remains the same, and the warehouse gets empty after serving M requests.
  • A new value XAB is written into register X which is calculated like this:
    XAB = (X · A + B) mod N
Suppose, that the customer requires K pieces. You must write a program that will calculate the sequence of pieces given out by the seller.

Input
The first line contains 5 integer numbers N, M, A, B, K (2 ≤ N, M ≤ 216; 1 ≤ KM; 0 < A < N; 0 ≤ B < N). The second line contains N integers - weights of pieces in the container. The third line contains M integers - weights of pieces in the warehouse. All weights are distinct. All weights are between 1 and 231-1 inclusively.
Output
Output K numbers separated by spaces - weights of pieces in order of giving out.

Input 1 Output 1
3 2 1 1 2
5 1 3
4 2
1 4
Input 2 Output 2
3 3 2 1 3
5 2 3
1 4 6
2 5 3

Для отправки решений необходимо выполнить вход.

www.contester.ru