DST Class Adventures - II

0

0 votes
Easy
Problem

This time, it is the next DST class, and today Professor has decided to teach linked list. Professor, being a pragmatic person, wants to take some practical examples. He wants to demonstrate insertion and deletion through a linked list. For this demonstration, he wants to change seating arrangements for the students. He sets some rule for the whole transaction which are:

(i) Only one student can move at a time during exchange
(ii) Students sitting at corner are the only students who can move

The initial configuration of the class is given. There will be k operations, where each operation will have three arguments, a, b, c, where a and b are initial and final rows and c represents a number of students from the left side of the initial row(first). After each operation, the c number of students from initial row sits to the right side of the final row. Your task is to take the print the final configuration of the class after each operation.

Hint:
- Check the number of students at rows for each operation. Use your logic before applying any seat exchange.

Input:
3 5
Q W E R T
A S D F G
Z X C V B
3
0 1 2 // 2 persons from the left side of 0th row goes to the right end of 1st row
1 2 3 // similarly, 3 persons from 1st row goes to the right end of 2nd row
2 0 1 // 1 person from 2nd row goes to the right end of 0th row

Output:
E R T
A S D F G Q W
Z X C V B

E R T
F G Q W
Z X C V B A S D

E R T Z
F G Q W
X C V B A S D

Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?