intwaterArea(vector<int> h){ int res = 0, l = 0, r = h.size() - 1, mi = 0; while(l < r) { while(l <= r and mi >= h[l]) l++; while(l <= r and mi >= h[r]) r--; if(l <= r) { res += (min(h[l], h[r]) - mi) * (r - l + 1); mi = min(h[l], h[r]); } } return res - accumulate(begin(h), end(h), 0); }