A company has employed N developers (numbered from 0 to N−1) and wants to divide them into two teams. The first is a front-end team with F developers. The second is a back-end team with N−F developers. If the K-th developer is assigned to the front-end team then their contribution is A[K], and if they are assigned to the back-end team then their contribution is B[K]. What is the maximum sum of contributions the company can achieve?
Write a function:
def solution(A, B, F)
that, given two arrays A, B (consisting of N integers each) and the integer F, returns the maximum sum of contributions the company can achieve.
Examples:
1. Given A = [4, 2, 1], B = [2, 5, 3] and F = 2, the function should return 10. There should be two front-end developers and one back-end developer. The 0th and 2nd developers should be assigned to the front-end team (with contributions 4 and 1) and the 1st developer should be assigned to the back-end team (with contribution 5).
2. Given A = [7, 1, 4, 4], B = [5, 3, 4, 3] and F = 2, the function should return 18. The 0th and 3rd developers should be assigned to the front-end team and the 1st and 2nd developers should be assigned to the back-end team.
3. Given A = [5, 5, 5], B = [5, 5, 5] and F = 1, the function should return 15. The 0th developer can be assigned to the front-end team and the 1st and 2nd developers can be assigned to the back-end team.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..200,000];
- arrays A and B have equal lengths;
- each element of array A is an integer within the range [0..1,000];
- F is an integer within the range [0..N].
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - [skill[1] for skill in f_b_skills]
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - [skill[1] for skill in f_b_skills]
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - [skill[1] for skill in f_b_skills]
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
f_b_diff
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - [skill[1] for skill in f_b_skills]
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
del f_b_diff[next_f]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - [skill[1] for skill in f_b_skills]
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
del f_b_diff[next_f]
f_counter += 1
b_programmers =
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - [skill[1] for skill in f_b_skills]
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
del f_b_diff[next_f]
f_counter += 1
b_programmers = set
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - [skill[1] for skill in f_b_skills]
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
del f_b_diff[next_f]
f_counter += 1
b_programmers = set([i for i in range(len(B))]) - f_programmers
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - [skill[1] for skill in f_b_skills]
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
del f_b_diff[next_f]
f_counter += 1
b_programmers = set([i for i in range(len(B))]) - f_programmers
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - [skill[1] for skill in f_b_skills]
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
del f_b_diff[next_f]
f_counter += 1
b_programmers = set([i for i in range(len(B))]) - f_programmers
comp_contr = 0
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - [skill[1] for skill in f_b_skills]
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
del f_b_diff[next_f]
f_counter += 1
b_programmers = set([i for i in range(len(B))]) - f_programmers
comp_contribution = 0
for
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - [skill[1] for skill in f_b_skills]
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
del f_b_diff[next_f]
f_counter += 1
b_programmers = set([i for i in range(len(B))]) - f_programmers
comp_contribution = 0
for i in
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - [skill[1] for skill in f_b_skills]
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
del f_b_diff[next_f]
f_counter += 1
b_programmers = set([i for i in range(len(B))]) - f_programmers
comp_contribution = 0
for i in range(len(A)):
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - [skill[1] for skill in f_b_skills]
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
del f_b_diff[next_f]
f_counter += 1
b_programmers = set([i for i in range(len(B))]) - f_programmers
comp_contribution = 0
for i in range(len(A)):
if i in b_programmers:
comp_contribution += A[i]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - [skill[1] for skill in f_b_skills]
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
del f_b_diff[next_f]
f_counter += 1
b_programmers = set([i for i in range(len(B))]) - f_programmers
comp_contribution = 0
for i in range(len(A)):
if i in b_programmers:
comp_contribution += A[i]
else:
comp_cotribution += B[i]
return comp_contribution
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - [skill[1] for skill in f_b_skills]
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
del f_b_diff[next_f]
f_counter += 1
b_programmers = set([i for i in range(len(B))]) - f_programmers
comp_contribution = 0
for i in range(len(A)):
if i in b_programmers:
comp_contribution += A[i]
else:
comp_cotribution += B[i]
return comp_contribution
Traceback (most recent call last): File "exec.py", line 143, in <module> main() File "exec.py", line 84, in main sol = __import__('solution') File "/tmp/solution.py", line 7 f_counter = 0 ^ SyntaxError: invalid syntax
Traceback (most recent call last): File "exec.py", line 143, in <module> main() File "exec.py", line 84, in main sol = __import__('solution') File "/tmp/solution.py", line 7 f_counter = 0 ^ SyntaxError: invalid syntax
Traceback (most recent call last): File "exec.py", line 143, in <module> main() File "exec.py", line 84, in main sol = __import__('solution') File "/tmp/solution.py", line 7 f_counter = 0 ^ SyntaxError: invalid syntax
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - skill[1] for skill in f_b_skills]
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
del f_b_diff[next_f]
f_counter += 1
b_programmers = set([i for i in range(len(B))]) - f_programmers
comp_contribution = 0
for i in range(len(A)):
if i in b_programmers:
comp_contribution += A[i]
else:
comp_cotribution += B[i]
return comp_contribution
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - skill[1] for skill in f_b_skills]
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
del f_b_diff[next_f]
f_counter += 1
b_programmers = set([i for i in range(len(B))]) - f_programmers
comp_contribution = 0
for i in range(len(A)):
if i in b_programmers:
comp_contribution += A[i]
else:
comp_cotribution += B[i]
return comp_contribution
Traceback (most recent call last): File "exec.py", line 143, in <module> main() File "exec.py", line 105, in main result = solution( A, B, F ) File "/tmp/solution.py", line 20, in solution comp_cotribution += B[i] UnboundLocalError: local variable 'comp_cotribution' referenced before assignment
Traceback (most recent call last): File "exec.py", line 143, in <module> main() File "exec.py", line 105, in main result = solution( A, B, F ) File "/tmp/solution.py", line 20, in solution comp_cotribution += B[i] UnboundLocalError: local variable 'comp_cotribution' referenced before assignment
Traceback (most recent call last): File "exec.py", line 143, in <module> main() File "exec.py", line 105, in main result = solution( A, B, F ) File "/tmp/solution.py", line 20, in solution comp_cotribution += B[i] UnboundLocalError: local variable 'comp_cotribution' referenced before assignment
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - skill[1] for skill in f_b_skills]
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
del f_b_diff[next_f]
f_counter += 1
b_programmers = set([i for i in range(len(B))]) - f_programmers
comp_contribution = 0
for i in range(len(A)):
if i in b_programmers:
comp_contribution += A[i]
else:
comp_contribution += B[i]
return comp_contribution
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - skill[1] for skill in f_b_skills]
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
del f_b_diff[next_f]
f_counter += 1
b_programmers = set([i for i in range(len(B))]) - f_programmers
comp_contribution = 0
for i in range(len(A)):
if i in b_programmers:
comp_contribution += A[i]
else:
comp_contribution += B[i]
return comp_contribution
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - skill[1] for skill in f_b_skills]
print(f_b_diff)
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
del f_b_diff[next_f]
f_counter += 1
b_programmers = set([i for i in range(len(B))]) - f_programmers
comp_contribution = 0
for i in range(len(A)):
if i in b_programmers:
comp_contribution += A[i]
else:
comp_contribution += B[i]
return comp_contribution
[2, -3, -2]
[2, -2, 0, 1]
[0, 0, 0]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - skill[1] for skill in f_b_skills]
print(f_b_diff)
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
del f_b_diff[next_f]
f_counter += 1
b_programmers = set([i for i in range(len(B))]) - f_programmers
comp_contribution = 0
for i in range(len(A)):
if i in b_programmers:
comp_contribution += A[i]
else:
comp_contribution += B[i]
return comp_contribution
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - skill[1] for skill in f_b_skills]
print(f_b_diff)
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
del f_b_diff[next_f]
f_counter += 1
b_programmers = set([i for i in range(len(B))]) - f_programmers
print(f_programmers)
comp_contribution = 0
for i in range(len(A)):
if i in b_programmers:
comp_contribution += A[i]
else:
comp_contribution += B[i]
return comp_contribution
[2, -3, -2] {0, 1}
[2, -2, 0, 1] {0, 2}
[0, 0, 0] {0}
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - skill[1] for skill in f_b_skills]
print(f_b_diff)
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
del f_b_diff[next_f]
f_counter += 1
b_programmers = set([i for i in range(len(B))]) - f_programmers
print(f_programmers)
comp_contribution = 0
for i in range(len(A)):
if i in b_programmers:
comp_contribution += A[i]
else:
comp_contribution += B[i]
return comp_contribution
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - skill[1] for skill in f_b_skills]
print(f_b_diff)
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
del f_b_diff[next_f]
print(next_f, f_b_diff)
f_counter += 1
b_programmers = set([i for i in range(len(B))]) - f_programmers
print(f_programmers)
comp_contribution = 0
for i in range(len(A)):
if i in b_programmers:
comp_contribution += A[i]
else:
comp_contribution += B[i]
return comp_contribution
[2, -3, -2] 0 [-3, -2] 1 [-3] {0, 1}
[2, -2, 0, 1] 0 [-2, 0, 1] 2 [-2, 0] {0, 2}
[0, 0, 0] 0 [0, 0] {0}
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - skill[1] for skill in f_b_skills]
print(f_b_diff)
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
del f_b_diff[next_f]
print(next_f, f_b_diff)
f_counter += 1
b_programmers = set([i for i in range(len(B))]) - f_programmers
print(f_programmers)
comp_contribution = 0
for i in range(len(A)):
if i in b_programmers:
comp_contribution += A[i]
else:
comp_contribution += B[i]
return comp_contribution
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
local_neg_inf
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - skill[1] for skill in f_b_skills]
print(f_b_diff)
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
del f_b_diff[next_f]
print(next_f, f_b_diff)
f_counter += 1
b_programmers = set([i for i in range(len(B))]) - f_programmers
print(f_programmers)
comp_contribution = 0
for i in range(len(A)):
if i in b_programmers:
comp_contribution += A[i]
else:
comp_contribution += B[i]
return comp_contribution
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
local_neg_inf = -1001
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - skill[1] for skill in f_b_skills]
print(f_b_diff)
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
del f_b_diff[next_f]
print(next_f, f_b_diff)
f_counter += 1
b_programmers = set([i for i in range(len(B))]) - f_programmers
print(f_programmers)
comp_contribution = 0
for i in range(len(A)):
if i in b_programmers:
comp_contribution += A[i]
else:
comp_contribution += B[i]
return comp_contribution
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
local_neg_inf = -1001
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - skill[1] for skill in f_b_skills]
print(f_b_diff)
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
f_b_diff[next_f] = local_neg_inf
print(next_f, f_b_diff)
f_counter += 1
b_programmers = set([i for i in range(len(B))]) - f_programmers
print(f_programmers)
comp_contribution = 0
for i in range(len(A)):
if i in b_programmers:
comp_contribution += A[i]
else:
comp_contribution += B[i]
return comp_contribution
[2, -3, -2] 0 [-1001, -3, -2] 2 [-1001, -3, -1001] {0, 2}
[2, -2, 0, 1] 0 [-1001, -2, 0, 1] 3 [-1001, -2, 0, -1001] {0, 3}
[0, 0, 0] 0 [-1001, 0, 0] {0}
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
local_neg_inf = -1001
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - skill[1] for skill in f_b_skills]
print(f_b_diff)
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
f_b_diff[next_f] = local_neg_inf
print(next_f, f_b_diff)
f_counter += 1
b_programmers = set([i for i in range(len(B))]) - f_programmers
print(f_programmers)
comp_contribution = 0
for i in range(len(A)):
if i in _programmers:
comp_contribution += A[i]
else:
comp_contribution += B[i]
return comp_contribution
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
local_neg_inf = -1001
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - skill[1] for skill in f_b_skills]
print(f_b_diff)
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
f_b_diff[next_f] = local_neg_inf
print(next_f, f_b_diff)
f_counter += 1
b_programmers = set([i for i in range(len(B))]) - f_programmers
print(f_programmers)
comp_contribution = 0
for i in range(len(A)):
if i in f_programmers:
comp_contribution += A[i]
else:
comp_contribution += B[i]
return comp_contribution
[2, -3, -2] 0 [-1001, -3, -2] 2 [-1001, -3, -1001] {0, 2}
[2, -2, 0, 1] 0 [-1001, -2, 0, 1] 3 [-1001, -2, 0, -1001] {0, 3}
[0, 0, 0] 0 [-1001, 0, 0] {0}
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
local_neg_inf = -1001
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - skill[1] for skill in f_b_skills]
#print(f_b_diff)
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
f_b_diff[next_f] = local_neg_inf
print(next_f, f_b_diff)
f_counter += 1
b_programmers = set([i for i in range(len(B))]) - f_programmers
#print(f_programmers)
comp_contribution = 0
for i in range(len(A)):
if i in f_programmers:
comp_contribution += A[i]
else:
comp_contribution += B[i]
return comp_contribution
0 [-1001, -3, -2] 2 [-1001, -3, -1001]
0 [-1001, -2, 0, 1] 3 [-1001, -2, 0, -1001]
0 [-1001, 0, 0]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
local_neg_inf = -1001
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - skill[1] for skill in f_b_skills]
#print(f_b_diff)
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
f_b_diff[next_f] = local_neg_inf
#print(next_f, f_b_diff)
f_counter += 1
b_programmers = set([i for i in range(len(B))]) - f_programmers
#print(f_programmers)
comp_contribution = 0
for i in range(len(A)):
if i in f_programmers:
comp_contribution += A[i]
else:
comp_contribution += B[i]
return comp_contribution
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
local_neg_inf = -1001
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - skill[1] for skill in f_b_skills]
#print(f_b_diff)
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
f_b_diff[next_f] = local_neg_inf
#print(next_f, f_b_diff)
f_counter += 1
b_programmers = set([i for i in range(len(B))]) - f_programmers
#print(f_programmers)
comp_contribution = 0
for i in range(len(A)):
if i in f_programmers:
comp_contribution += A[i]
else:
comp_contribution += B[i]
return comp_contribution
function result: 12
function result: 18
function result: 24
function result: 3
function result: 4
function result: 10
[[7, 8, 9], [1, 2, 3], 1]
[[7, 8, 9], [1, 2, 3], 2]
[[7, 8, 9], [1, 2, 3], 3]
[[3], [4], 1]
[[4], [3], 1]
[[3, 4], [5, 7], 1]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
local_neg_inf = -1001
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - skill[1] for skill in f_b_skills]
#print(f_b_diff)
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
f_b_diff[next_f] = local_neg_inf
#print(next_f, f_b_diff)
f_counter += 1
b_programmers = set([i for i in range(len(B))]) - f_programmers
#print(f_programmers)
comp_contribution = 0
for i in range(len(A)):
if i in f_programmers:
comp_contribution += A[i]
else:
comp_contribution += B[i]
return comp_contribution
function result: 12
function result: 18
function result: 24
function result: 3
function result: 4
function result: 10
[[7, 8, 9], [1, 2, 3], 1]
[[7, 8, 9], [1, 2, 3], 2]
[[7, 8, 9], [1, 2, 3], 3]
[[3], [4], 1]
[[4], [3], 1]
[[3, 4], [5, 7], 1]
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
local_neg_inf = -1001
def solution(A, B, F):
f_b_skills = list(zip(A, B))
f_b_diff = [skill[0] - skill[1] for skill in f_b_skills]
#print(f_b_diff)
f_counter = 0
f_programmers = set()
while f_counter < F:
next_f = f_b_diff.index(max(f_b_diff))
f_programmers.add(next_f)
f_b_diff[next_f] = local_neg_inf
#print(next_f, f_b_diff)
f_counter += 1
b_programmers = set([i for i in range(len(B))]) - f_programmers
#print(f_programmers)
comp_contribution = 0
for i in range(len(A)):
if i in f_programmers:
comp_contribution += A[i]
else:
comp_contribution += B[i]
return comp_contribution
The following issues have been detected: timeout errors.
N = 20. Some developers have small difference between A[i] and B[i].
N = 300. Some developers have small difference between A[i] and B[i].
N = 200,000. Large random tests.
Killed. Hard limit reached: 8.000 sec.
N = 200,000. A[i] > B[i].
Killed. Hard limit reached: 8.000 sec.
N = 200,000. Some developers have small difference between A[i] and B[i].
Killed. Hard limit reached: 8.000 sec.
N is maximal, upper corner cases.
Killed. Hard limit reached: 8.000 sec.