My code: didn’t passed all testcase:
#include<bits/stdc++.h> using namespace std; int main() { int n,k; int a[100]; cin>>n; cin>>k; for(int i=0; i<n; i++) { cin>>a[i]; } if(a[k]==0 && a[k+1]==0) { cout<<"0"; } else if(a[k]==1 && a[k+1]==1) { cout<<"5"; } else if(n==k) { cout<<n; } else if(a[k-1]==a[(k-1)+1]) { printf("%d",k+1); } else if(a[k]>a[k+1]) { cout<<k; } return 0; }
Then looked out the solution but din’t understand one thing but implemented my own:
#include<bits/stdc++.h> using namespace std; int main() { int n,k; int a[100]; cin>>n; cin>>k; for(int i=0; i<n; i++) { cin>>a[i]; } int counter=0; int margin=a[k-1]; for(int i=0; i<n; i++) { if(a[i]>=margin && a[i]) //10 >= 7 && 10//i have confusion in >=&&a[i] { counter++; } } cout<<counter; return 0; }
http://itisadumbblog.blogspot.com/2015/05/codeforces-158a-next-round-solution.html