CSE221 Lab 02 Fall 24
CSE221 Lab 02 Fall 24
Task 01:
Now you are feeling very tired. So you decided to write a code,
so that it can give you the answer very quickly.
Input
The first line contains two integers N and S (1 <= N <= 105, 1 <=
S <= 109), denoting the length of the list, and the target Sum.
Output
6 18 3 6
1 5 8 9 9 10
[4 5 is also a valid answer]
[print only one output]
4 7 IMPOSSIBLE
2 4 6 8
4 10 IMPOSSIBLE
1 5 6 8
Task 02:
Alice and Bob are two friends. Alice has a sorted list in
ascending order of length N. On the other hand, Bob has a sorted
list of length M. Now, they want to make a sorted list of N+M
length in ascending order. However, they are not very good at
algorithms. Hence, they asked for your help.
Input
All the numbers given in the input will fit in a 32-bit signed
integer.
Output:
You have to make a sorted list in ascending order from the given
sorted lists and show the output.
Sample Input/Output:
4 1 2 2 3 4 5 7 8
1 3 5 7
4
2 2 4 8
3 2 3 4 6 7 8 9 10 12
2 10 12
6
3 4 6 7 8 9
4 1 2 3 4 10
1 2 3 4
1
10
7 1 1 2 3 4 5 6 8 8 8 10 12 13 14
2 3 8 8 10 12 14 15 16
9
1 1 4 5 6 8 13 15 16
Task 3
You are a busy person with lots of tasks to do. You have a
schedule of tasks represented by intervals of time, where each
interval represents a task that you need to complete. However,
you can only work on one task at a time, and you want to complete
as many tasks as possible.
Input
Output
Sample Input/Output:
6 3
1 3 1 3
2 5 4 6
3 7 6 8
4 6
6 8
7 9
5 2
1 4 1 4
2 5 6 7
6 7
4 8
3 6
7 5
0 4 1 2
3 4 2 3
1 5 3 4
9 10 6 9
6 9 9 10
2 3
1 2
Task 4
Given N tasks and M people, where each task has a start time and
end time, implement a greedy algorithm to find the maximum number
of tasks that can be completed by M people.
Each task can only be completed by one person and a person can
only be assigned one task at a time. Two tasks cannot be
completed simultaneously by the same person.
Input
Output
Sample Input/Output:
5 2 4
1 5
3 6
2 5
8 10
6 9
5 2 4
1 4
2 5
6 7
4 8
3 6
6 2 5
1 5
4 10
8 17
12 15
9 11
14 18
8 3 8
5 7
2 4
6 8
8 10
1 3
7 9
3 5
2 6
In sample input 2-