Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save KhaledElshamy/ef3e1eed1f1b665dff94318eb3540ec2 to your computer and use it in GitHub Desktop.

Select an option

Save KhaledElshamy/ef3e1eed1f1b665dff94318eb3540ec2 to your computer and use it in GitHub Desktop.
Bear and Finding Criminals
// working.cpp by Bill Weinman <http://bw.org/>
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,in;
cin>>n>>in;
int a[n];
for (int i=1;i<=n;i++)
cin>>a[i];
int ans=0;
int l=in-1,r=in+1;
while(l>=1&&r<=n)
{
if (a[l]==1&&a[r]==1)
{
ans+=2;
}
l--,r++;
}
if (l==0)
{
for (int i=r;i<=n;i++)
{
if (a[i]==1)
ans++;
}
}
if (r==n+1)
{
for (int i=l;i>=0;i--)
{
if (a[i]==1)
ans++;
}
}
if (a[in]==1)
ans++;
cout<<ans<<endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment