fork download
  1. int solve(vector<int>& height) {
  2. int n = height.size();
  3. vector<int> leftMax(n), rightMax(n);
  4. for (int i = 1; i < n; ++i)
  5. leftMax[i] = max(height[i-1], leftMax[i-1]);
  6. for (int i = n-2; i >= 0; --i)
  7. rightMax[i] = max(height[i+1], rightMax[i+1]);
  8.  
  9. int ans = 0;
  10. for (int i = 0; i < n; ++i) {
  11. int waterLevel = min(leftMax[i], rightMax[i]);
  12. if (waterLevel >= height[i]) ans += waterLevel - height[i];
  13. }
  14. return ans;
  15.  
  16. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:11: error: ‘vector’ was not declared in this scope
 int solve(vector<int>& height) {
           ^~~~~~
prog.cpp:1:18: error: expected primary-expression before ‘int’
 int solve(vector<int>& height) {
                  ^~~
stdout
Standard output is empty