Created
March 6, 2015 04:55
-
-
Save enghqii/75f0b393aace4198ae4c to your computer and use it in GitHub Desktop.
fence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <set> | |
using namespace std; | |
int main(){ | |
int testcase = 0; | |
cin>>testcase; | |
while(testcase--){ | |
int nFence = 0; | |
cin>>nFence; | |
vector<int> fences; | |
set<int> heights; | |
int maxHeight = 0; | |
for(int i = 0; i < nFence; i++){ | |
int val = 0; | |
cin>>val; | |
fences.push_back(val); | |
heights.insert(val); | |
maxHeight = maxHeight < val ? val : maxHeight; | |
} | |
int result = 0; | |
for(int height : heights){ | |
int maxArea = 0; | |
int curArea = 0; | |
for(int e : fences){ | |
if(e >= height){ | |
curArea += height; | |
}else{ | |
curArea = 0; | |
} | |
maxArea = maxArea < curArea ? curArea : maxArea; | |
} | |
//cout<<"height : "<<height<<" maxArea : "<<maxArea<<endl; | |
result = result < maxArea ? maxArea : result; | |
} | |
cout<<result<<endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment