Created
September 16, 2024 10:02
-
-
Save AashishNandakumar/8fe8591f6ed4a7cf9f3bb03a358867d6 to your computer and use it in GitHub Desktop.
Cimpress Solutions
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
def logic(N, M, F, B): | |
# logic here | |
frontend = {} | |
backend = {} | |
for i in range(N + M): | |
frontend[i] = F[i] | |
backend[i] = B[i] | |
frontend = dict(sorted(frontend.items(), key=lambda x: x[1])) | |
backend = dict(sorted(backend.items(), key=lambda x: x[1])) | |
# print(f"Frontend: {frontend}; Backend: {backend}") | |
frontend_cost = set() | |
backend_cost = set() | |
for key, value in frontend.items(): | |
if ( | |
len(frontend_cost) < N | |
and key not in frontend_cost | |
and value <= backend[key] | |
): | |
frontend_cost.add(key) | |
elif ( | |
len(backend_cost) < M and key not in backend_cost and backend[key] <= value | |
): | |
backend_cost.add(key) | |
if len(frontend_cost) == N and len(backend_cost) == M: | |
break | |
total_frontend_cost = sum([frontend[cost] for cost in frontend_cost]) | |
total_backend_cost = sum([backend[cost] for cost in backend_cost]) | |
return total_frontend_cost + total_backend_cost | |
N = 2 | |
M = 1 | |
F = [1, 1, 1] | |
B = [1, 1, 1] | |
res = logic(N, M, F, B) | |
print(res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment