//use two pointers: move the shorter one until they meet in the middle
class Solution {
public:
int maxArea(vector<int> &height) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int size=height.size();
if(size<2)
return -1;
int i=0,j=size-1,temp=0,max=0;
while(i<j){
temp=(j-i)*(height[i]<height[j]?height[i]:height[j]);
max=max<temp?temp:max;
if(height[i]<height[j])
while(height[i]>height[++i]);
else
while(height[j]>height[--j]);
}
return max;
}
};