fork download
  1. #include <bits/stdc++.h>
  2. #define mod 1000000007
  3. #define lng long long
  4.  
  5. using namespace std;
  6. const double PI = 3.141592;
  7. const lng int INF_LL = (lng)(1e18);
  8. const int INF = 0x7fffffff;
  9.  
  10. int main(){
  11. std::ios::sync_with_stdio(false);
  12. freopen("input.txt","r",stdin);
  13. freopen("output.txt","w",stdout);
  14. int n;
  15. cin>>n;
  16. int arr[n+1],pos[n+1],neg[n+1];
  17.  
  18. for(int i=1;i<=n;i++){
  19. cin>>arr[i];
  20. }
  21. pos[0]=0;
  22. neg[0]=0;
  23.  
  24. for(int i=1;i<=n;i++){
  25. if(arr[i]<0){
  26. neg[i]=neg[i-1]+1;
  27. pos[i]=pos[i-1];
  28. }
  29. else if(arr[i]>0){
  30. pos[i]=pos[i-1]+1;
  31. neg[i]=neg[i-1];
  32. }
  33. else{
  34. neg[i]=neg[i-1];
  35. pos[i]=pos[i-1];
  36. }
  37. }
  38. int ans=INF;
  39. for(int i=1;i<n;i++){
  40. ans=min(ans,n-neg[i]-pos[n]+pos[i]);
  41. }
  42. cout<<ans<<endl;
  43. return 0;
  44. }
Runtime error #stdin #stdout #stderr 0s 3464KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::ios_base::failure'
  what():  basic_filebuf::underflow error reading the file