Card ShuffleProblem code: CARDSHUF |
All submissions for this problem are available.
Chef is organizing an online card game tournament and for this purpose he has to provide a card shuffling software. This software has to simulate the following shuffling process. A stack of N cards is placed face down on the table. Cards in the stack are ordered by value. Topmost card has value 1 and the one on the bottom has value N. To shuffle the cards we repeat the following steps M times:
- take A cards from the top of the deck.
- take another B cards from the top of the deck.
- put the A cards, which you removed in the first step, back on top of the remaining deck.
- take C cards from the deck
- put the B cards, which you're still holding from the second move, card by card on top of the deck.
- finally, return the block of C cards on top
Input
The first line contains integers N and M. The following M lines describe the moves by integers Ai, Bi, Ci as described in the previous section.
In the spirit of random card shuffling, all test cases were generated with uniform random distributions to select where to cut the deck of cards.
Output
In a single line output the cards in the deck after performing all the moves. Cards should be listed from top of the deck to bottom and separated by spaces.
Constraints
- 1 <= N, M <= 100 000
Example
Input: 10 2 6 2 2 5 3 6 Output: 1 2 8 7 3 9 6 5 4 10
| Author: | thocevar |
| Tester: | laycurse |
| Editorial | http://discuss.codechef.com/problems/CARDSHUF |
| Date Added: | 7-12-2011 |
| Time Limit: | 6 sec |
| Source Limit: | 50000 Bytes |
| Languages: | ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC |
Comments
SUCCESSFUL SUBMISSIONS
Fetching successful submissions


i think the in the output we
@ron2794 Why? Output should
oh ok..i counted those lines
can a,b,c equal to 0 ?
B is at least 1 in the test
Dear admin, I keep getting
http://www.codechef.com/wiki/
my code is working fine..on
can the number of cards in
how can onlyn_judge accept
what is the higher limit of n
can you provide more test
@sumit4iit: I checked your
@vamsi_algo: I think it's
@imscorpion: Further cases
@admin: what should happen
@acpaluri: Test cases contain
I tried may times... It's
Will brute force algorithm
@jainharshit: You have to
@admin: I'm getting TLE using
@samridh90
What can be the maximum
@nikhil_kataria: As
i keep getting a compile
got rid of that error and got
where l be runtime error
@admin my submission id is
@sehrawat.parshant: I can't
@admin: My submission has an
@rahulsuresh: Extra
i am getting run time error