FPDMACHINE - Editorial

PROBLEM LINK:

Practice
Contest

Author: Riddhish Lichade
Tester: Yogesh Deolalkar
Editorialist: Prathamesh Sogale

DIFFICULTY:

EASY

PROBLEM:

EXPLANATION:

Meena can eat the food packets from those buildings who are at same distance and both the buildings contains a food packet. If one building contains it and other building at the same distance doesn’t contain it, then he can’t eat it.
He will also eat the food packet if there is only one building at that distance and it has a food packet.

SOLUTIONS:

Setter's Solution
from sys import stdin
for _ in range(int(stdin.readline())):
    n, a = map(int, stdin.readline().strip().split())
    l=list(map(int, stdin.readline().strip().split()))
    if(n==a or a==1):
        print(l.count(1))
        continue
    l1=l[:a-1]
    l1.reverse()
    l2=l[a:]
    l2len=n-a
    l1len=a-1
    count=l[a-1]
    mini=min(l2len,l1len)
    for i in range(mini):
        if(l1[0]==1 and l2[0]==1):
            count+=2
        l1.pop(0)
        l2.pop(0)
    count+=l1.count(1)
    count+=l2.count(1)
    print(count)