fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5. int n; // declare n to be a number
  6. cin>>n; // read n from the input
  7. // declare "books" to be a sequence of numbers of length n:
  8. vector<int> books(n);
  9. for(int i=0;i<n;i=i+1)
  10. cin>>books[i]; // read books from the input
  11. int result=0; // declare result to be a number which is initially 0
  12. int current=0; // declare current to be a number which is initially 0
  13. for(int i=0;i<n-1;i=i+1){ // for each i from 0 to n-2 in turn
  14. // if the number of the book at position i+1 is smaller
  15. // than the number of the book at position i:
  16. if(books[i+1]<books[i]){
  17. current = current + 1; // increase current by one
  18. }
  19. result = result + current; // increase result by current
  20. }
  21. cout<<n-result<<'\n'; // write n-result to the output
  22. }
  23.  
Success #stdin #stdout 0s 3416KB
stdin
7
2 5 3 4 7 1 6
stdout
0