-
Notifications
You must be signed in to change notification settings - Fork 0
/
fence1.cpp
45 lines (35 loc) · 910 Bytes
/
fence1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int solve(vector<int>& fences) {
int maxSize = 0;
int maxHeight = *max_element(fences.begin(), fences.end());
for (int h = 1; h <= maxHeight; ++h) {
int w = 0;
for (int i = 0; i < fences.size(); ++i) {
if (fences[i] >= h) ++w;
else {
maxSize = max(w * h, maxSize);
w = 0;
}
}
maxSize = max(w * h, maxSize);
}
return maxSize;
}
int main()
{
int numTestCase;
cin >> numTestCase;
for (int i = 0; i < numTestCase; ++i) {
int numFence;
cin >> numFence;
vector<int> fences(numFence);
for (int j = 0; j < numFence; ++j) {
cin >> fences[j];
}
cout << solve(fences) << endl;
}
return 0;
}