fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int n;
  6. cin>>n;
  7. vector<int> arr(n);
  8. for(int i=0;i<n;i++ )
  9. {
  10. cin>>arr[i];
  11. }
  12. int l=0,r=n-1;
  13. int fo=-1;
  14. while(l<=r)
  15. {
  16. int mid=(l+r)/2;
  17. if(arr[mid]==0)
  18. {
  19. l=mid+1;
  20. }
  21. else
  22. {
  23. fo=mid;
  24. r=mid-1;
  25.  
  26. }
  27. }
  28. cout<<fo;
  29.  
  30. return 0;
  31. }
Success #stdin #stdout 0.01s 5308KB
stdin
Standard input is empty
stdout
-1