-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmaxi.py
More file actions
60 lines (51 loc) · 1.49 KB
/
maxi.py
File metadata and controls
60 lines (51 loc) · 1.49 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
### Only 12 percent evaluation percent, check for any other testcases
# Given
# A = Array of trees with no of apples
# K = number of consec trees Alice can pick
# L = number of consec trees Bob can pick
# Choose: disjoint set and consecutive trees
# Logic1: For K and L, choose the greatest pair that would work. Use them.
# * Initially choose the greatest pair for alice, eliminate it and then greates pair for bob
def solution(A, K, L):
# Given data
n = len(A)
# Initial condition - Possibility of disjoint sets
total = K + L
if n < total:
return -1
# Alice condition - All possible sum value of Alice
alice = {}
for i in range(n-(K-1)):
value = 0
key = ""
j = i
count = 0
while count < K:
value += A[j]
key += str(j)
j += 1
count += 1
alice.update({key:value})
#print(alice)
# Bob condition - All possible sum value of Bob
bob = {}
for i in range(n-(L-1)):
value = 0
key = ""
j = i
count = 0
while count < L:
value += A[j]
key += str(j)
j += 1
count += 1
bob.update({key:value})
#print(bob)
# maximum disjoint
maxi = -600000
for k,v in alice.items():
for k1,v1 in bob.items():
result = v + v1
if result > maxi and k not in k1:
maxi = result
return maxi