Suggestions logoSuggestions

Questions

Selected practice problems and challenges for Competitive Programming II.

1. 19A - World Football Cup

Solve 19A - World Football Cup.

2. 235B - Let's Play Osu!

Solve 235B - Let's Play Osu!.

3. Student Management Portal

Develop a student management portal in C++. The portal stores a list of student IDs and supports the following queries:

  • Register ID: Add ID to the list.
  • Search ID: Print FOUND if ID exists; otherwise, print NOT FOUND.
  • Remove duplicates: Remove duplicate IDs from the list.
  • Delete ID: Delete the first occurrence of ID if it exists.

Commands are case-insensitive. After each query, print the current list of IDs. For a search query, print the search result before the list.

Input

The first line contains an integer T, the number of queries. Each of the next T lines contains one query.

Output

For each query, print the required result and the current list of IDs as described above.

Sample Input

10
Register 101
Register 102
Register 101
Search 102
Remove duplicates
Register 103
delete 101
Search 101
Register 104
delete 105

Sample Output

101
101 102
101 102 101
FOUND
101 102 101
101 102
101 102 103
102 103
NOT FOUND
102 103
102 103 104
102 103 104

4. CPU Task Scheduler

A CPU has nn tasks to execute. Each task has an ID, priority, and execution time.

If tasks have the same priority, they execute in First In First Out (FIFO) order. The CPU always executes the highest priority task first.

Determine:

  1. The order in which the tasks are executed
  2. The total time taken
  3. The completion time of each task

Input

The first line contains an integer nn, the number of tasks. Each of the next nn lines contains three space-separated integers representing the task ID, priority, and execution time.

Output

Print the execution order with the completion time of each task, followed by the total time taken.

Sample Input

6
1 3 4
2 1 2
3 4 6
4 2 5
5 4 3
6 1 7

Sample Output

Execution Order:
Task 3 completes at 6
Task 5 completes at 9
Task 1 completes at 13
Task 4 completes at 18
Task 2 completes at 20
Task 6 completes at 27
Total time = 27

5. Minimum Swaps to Sort Employee IDs

A company stores employee IDs in an array. You are allowed to swap only adjacent elements. Find the minimum number of adjacent swaps required to arrange the IDs in ascending order.

Input

The first line contains an integer nn, the number of employee IDs. The second line contains nn space-separated integers representing the employee IDs.

Output

Print the state of the array after each adjacent swap, followed by the minimum number of adjacent swaps required on the final line.

Sample Input

5
5 1 4 2 3

Sample Output

1 5 4 2 3 
1 4 5 2 3 
1 4 2 5 3 
1 4 2 3 5 
1 2 4 3 5 
1 2 3 4 5 
6

6. Robot Navigation

A robot starts at position (0, 0) on a 2D grid. You are given a string containing movement commands:

  • L: Move one step left (x1,yx - 1, y)
  • R: Move one step right (x+1,yx + 1, y)
  • U: Move one step up (x,y+1x, y + 1)
  • D: Move one step down (x,y1x, y - 1)

The robot executes the commands one by one. Determine the robot's final coordinates (x, y) and whether the robot visited any coordinate more than once (including the starting position (0, 0)).

Print Yes if any position was visited more than once; otherwise, print No.

Input

Each line of input contains a non-empty string consisting of the characters L, R, U, and D.

Output

For each test case, print the final coordinates in the format (x, y) on the first line, followed by Yes or No on the second line.

Sample Input

UURR
LR
LDRLDU

Sample Output

(2, 2)
No
(0, 0)
Yes
(-1, -1)
Yes

On this page