-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.py
More file actions
32 lines (27 loc) · 748 Bytes
/
Test.py
File metadata and controls
32 lines (27 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def findProduct(A):
result = 1
isNegative = False
for x in A:
result = result * x
if x < 0:
isNegative = True
return result, isNegative
def func(N, K, M, A):
for i in range(M):
product, isNegative = findProduct(A)
if not isNegative:
smallestIndex = A.index(min(A))
A[smallestIndex] -= K
else:
largest = A[0]
largestNegativeIndex = 0
for i in range(len(A)):
if A[i] < 0 and A[i]>largest:
largestNegativeIndex = i
A[largestNegativeIndex] += K
return findProduct(A)[0]
N = 5
M = 2
K = 3
A = [1,3,-6,-5,-4]
print(func(N, K, M, A))