Created
January 18, 2017 23:24
-
-
Save KhaledElshamy/ef3e1eed1f1b665dff94318eb3540ec2 to your computer and use it in GitHub Desktop.
Bear and Finding Criminals
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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