USE PYTHON LANGUAGE. READ INPUT FROM FILE (NAME THE FILE "input.txt') The problem needs to be solved using Greedy Algorithm Strategy. Problem: . Each activity has a time interval- i.e. a start and a finish time. The activities can be distributed between M people. Implement a greedy algorithm to find the total number of activities that can be completed by M people. The following conditions must be met when writing the code: One person cannot do activities with overlapping time intervals, so each person can do only one activity at a given time interval. Each activity can be completed by only one person. The input will contain N and M, and then N lines with the start time and finish time in the format given below: N M S₁ F₁ S₂ F₂ ……. Sn Fn You have to read input from a file. The output will contain the total number of activities that can be completed. Sample input and output are given below. Name your input file “input.txt”. Make sure to try out different input examples to ensure that your code is working for different cases. Include the input file in your zipped submission folder. Input 1: 5 2 1 5 3 6 2 5 8 10 6 9 Input 2: 3 2 3 6 2 4 2 3 Output 1: 4 Output 2: 3 The image pseudocode has been given. You have to modify the pseudocode to solve the problem.
USE PYTHON LANGUAGE.
READ INPUT FROM FILE (NAME THE FILE "input.txt')
The problem needs to be solved using Greedy
Problem:
. Each activity has a time interval- i.e. a start and a finish time. The activities can be distributed between M people. Implement a greedy algorithm to find the total number of activities that can be completed by M people. The following conditions must be met when writing the code:
- One person cannot do activities with overlapping time intervals, so each person can do only one activity at a given time interval.
- Each activity can be completed by only one person.
The input will contain N and M, and then N lines with the start time and finish time in the format given below:
N M
S₁ F₁
S₂ F₂
…….
Sn Fn
You have to read input from a file. The output will contain the total number of activities that can be completed. Sample input and output are given below. Name your input file “input.txt”. Make sure to try out different input examples to ensure that your code is working for different cases. Include the input file in your zipped submission folder.
Input 1: 5 2 1 5 3 6 2 5 8 10 6 9 |
Input 2: 3 2 3 6 2 4 2 3 |
Output 1: 4 |
Output 2: 3 |
The image pseudocode has been given. You have to modify the pseudocode to solve the problem.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 6 images