Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rishabhgargg/7526a9ed91b1c429313b358664365ee7 to your computer and use it in GitHub Desktop.
Save rishabhgargg/7526a9ed91b1c429313b358664365ee7 to your computer and use it in GitHub Desktop.
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