Greedy load balance

Report a typo

Write a program that implements a simple load balancer.

The program must read tasks from the standard input and distribute them between two queues. Tasks will be processed by a system (in the future). Each task has a unique identifier and a number indicating the load on the system (in parrots).

The balancer should distribute tasks between queues by the following rule: the task is added to the lower-load queue (by the total load). If both queues have the same total load indicator, the task must be added to the first queue.

It's guaranteed that the input data contains at least two tasks.

Input data format

The first line contains the number of tasks. Other lines consist of task description: an identifier and a load indicator (separated by a space).

Output data form

The first line should contain identifiers of tasks in the first queue, the second line should contain the identifiers in the second queue.

Sample Input 1:

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

Sample Output 1:

1 3 5 6
2 4
Write a program in Java 17
class Main {
public static void main(String[] args) {
// put your code here
}
}
___

Create a free account to access the full topic