Skip to content

Commit fef0c5c

Browse files
authored
Merge pull request #18 from shekhuverma/master
added python solutions
2 parents c8a737f + 2832e8f commit fef0c5c

File tree

2 files changed

+49
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)