Skip to content

Commit 1cb1b66

Browse files
committed
Added python solutions
1 parent 80d7a6f commit 1cb1b66

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Write your code here
2+
N=map(int,raw_input().split())
3+
arr=map(int,raw_input().split())
4+
s=0 #To save the sum
5+
l=0 #To save the result
6+
if (max(arr)<0 and min(arr)<0):
7+
s=max(arr)
8+
l=1
9+
else:
10+
for a in arr:
11+
if a>=0:
12+
s+=a
13+
l+=1
14+
print s,l
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
def solution (A, K):
2+
# Write your code here
3+
ans=0 #To save the result
4+
if K > len(A):
5+
for row in A:
6+
ans+=(min(row.count("T"),row.count("P")))
7+
return ans
8+
9+
for row in A:
10+
arr_len = len(row)
11+
for i in range(arr_len):
12+
if row[i] == 'P':
13+
thieve_found = False
14+
for thief in range(max(0,i-K),min(i+K+1,arr_len)):
15+
if row[thief] == 'T':
16+
row[thief] = 'X'
17+
thieve_found = True
18+
break
19+
20+
if thieve_found:
21+
ans += 1
22+
return ans
23+
24+
25+
26+
T = input()
27+
for _ in xrange(T):
28+
N, K = map(int, raw_input().split())
29+
A = []
30+
for _ in xrange(N):
31+
A.append(raw_input().split())
32+
out_ = solution(A, K)
33+
print out_

0 commit comments

Comments
 (0)