Created
August 9, 2024 07:58
-
-
Save rishabhgargg/7526a9ed91b1c429313b358664365ee7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import deque | |
def min_weeks_to_serve(n, k, m, customers, requests): | |
requests_queue = deque(requests) | |
last_served = {customer: -float('inf') for customer in customers} # Initialize to a very early week | |
current_week = 0 | |
while requests_queue: | |
current_week += 1 | |
customer = requests_queue.popleft() | |
if last_served[customer] + m <= current_week: | |
last_served[customer] = current_week | |
else: | |
requests_queue.append(customer) | |
current_week -= 1 # We couldn't serve this week | |
return current_week | |
# Read input (Assuming you have a way to get this input) | |
n, k, m = map(int, input().split()) | |
customers = input().split() | |
requests = input().split() | |
# Calculate and print the result | |
result = min_weeks_to_serve(n, k, m, customers, requests) | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment