CLSLDR - Class Leader
This is new year in Planet X and there is something special! A classroom in this planet is looking for a new class leader using an unique game!
These are the ways how the game is played.
1. There are n students in the class. Each student is labeled from 1 (first student) to n (last student).
2. A paper is given to m-th student.
3. The next o-th student who gets the paper quits the game.
4. The paper is passed until there is one last student who hasn't quitted the game.
5. The student becomes the class leader.
Now, your task is to find the number of such student.
The first line contains a number T (0 <= T <= 106).
Each of the next T lines contains 3 integers which are n (0 < n <= 103), m, o (0 < m, o <= n) and are separated by a single space.
For each test cases, print the required answer.
4 1 2
5 2 3 Output: 2
Explanation for test case 1
1 2 3 4 -> The paper is being held by student 1. Pass the paper by 2 students. Now, the paper is being held by student 3.
1 2 4 -> Student 3 quits. Pass the paper by 2 students. Now, the paper is being held by student 1.
2 4 -> Student 1 quits. Pass the paper by 2 students. Now, the paper is being held by student 4.
2 -> Student 4 quits. Student 2 becomes the class leader.
time limit exceeded problem .. dont know where to reduce complexityLast edit: 2019-10-06 18:25:02
Please remove this problem if you don't want us to be able to solve it. I have never seen so stupid time limit.
It looks like the input test cases do not satisfy given constraints (probably last one):
TLE with O(n) approach any suggestion
are you sure with all of your testcases? please check again.