Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #4 sep
- if __name__ == "__main__":
- n = int(input("Enter the number of jobs: "))
- jobs = []
- print("Enter profit and deadline (space-separated) for each job:")
- for i in range(n):
- profit, deadline = map(int, input().split()) # Read profit and deadline as space-separated inputs
- jobs.append((profit, deadline, i + 1))
- jobs = sorted(jobs, key=lambda x: x[0], reverse=True)
- max_deadline = max(jobs, key=lambda x: x[1])[1]
- sz = [0] * max_deadline # Initialize a list to store the job schedule
- total_profit = 0
- for i in range(n):
- current_deadline = jobs[i][1]
- while current_deadline > 0:
- if sz[current_deadline - 1] == 0:
- sz[current_deadline - 1] = jobs[i][2]
- total_profit += jobs[i][0]
- break
- current_deadline -= 1
- print("Maximum profit:", total_profit)
- print("Job schedule:", sz)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement