fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. // Brute force
  5. int main() {
  6. int n = 5;
  7. int arr[] = {8, 2, 5, 1,10};
  8. int k = 5;
  9. int cnt = 0;
  10.  
  11. for(int i = 0 ; i < n ; i++){
  12. int maxElem = arr[i];
  13. for(int j = i ; j < n ; j++){
  14. maxElem = max(maxElem,arr[j]);
  15. if(maxElem == k)
  16. cnt++;
  17. }
  18. }
  19. cout<<cnt<<endl;
  20. return 0;
  21. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
4