Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.

Commit 9fa106b

Browse files
committed
Part 3 and 4 are done
1 parent 4e4f40c commit 9fa106b

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

.DS_Store

0 Bytes
Binary file not shown.

CA1/.DS_Store

6 KB
Binary file not shown.
File renamed without changes.

CA1/Question4.py

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
def sum_calculator(numbers,x) :
2+
sum_ = 0
3+
for idx,bit in enumerate(x) :
4+
number = numbers[idx]
5+
if bit == 1:
6+
sum_ += number
7+
return sum_
8+
9+
def main():
10+
n = int(input())
11+
numbers = list()
12+
for x in input().split():
13+
x = int(x)
14+
numbers.append(x)
15+
max = input()
16+
i = 0
17+
sum_zero = 0
18+
zero_list = list()
19+
numbers = numbers[::-1]
20+
j = 0
21+
x_max = [0] * n
22+
for element in max[::-1]:
23+
element = int(element)
24+
if numbers[j] > 0 and element == 0 :
25+
i += 1
26+
sum_zero += numbers[j]
27+
zero_list.append(j)
28+
elif numbers[j] > 0 and element == 1 :
29+
if(sum_zero > numbers[j]) :
30+
for test in zero_list :
31+
x_max[test] = 1
32+
zero_list = list()
33+
zero_list.append(j)
34+
i = 1
35+
sum_zero = numbers[j]
36+
else :
37+
x_max[j] = 1
38+
elif numbers[j] <= 0 and element == 1:
39+
if(i > 0) :
40+
sum_zero = 0
41+
for test in zero_list :
42+
x_max[test] = 1
43+
zero_list = list()
44+
i = 0
45+
x_max[j] = 0
46+
j += 1
47+
48+
# Printing the results
49+
t = len(x_max) - 1
50+
while t >= 0 :
51+
print(x_max[t], end='')
52+
t -= 1
53+
print("\n" + str(sum_calculator(numbers,x_max)))
54+
main()

0 commit comments

Comments
 (0)