fork(2) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int v[] = {1, 2, 3, 4, 6, 3, 2, 4, 7, 3, 4, 6, 1, 2, 1};
  7. int count = 0;
  8. for (int l=0,r=sizeof(v)/sizeof(v[0]),lM = v[0], rM = v[sizeof(v)/sizeof(v[0])];
  9. l < r;
  10. lM = max(lM,v[l]), rM = max(rM,v[r]))
  11. if(lM >= rM)
  12. count += rM - v[r--];
  13. else
  14. count += lM - v[l++];
  15. cout << count<<endl;
  16. return 0;
  17. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
15