-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path755.cpp
More file actions
47 lines (42 loc) · 768 Bytes
/
Copy path755.cpp
File metadata and controls
47 lines (42 loc) · 768 Bytes
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
46
47
#include<iostream>
#include<stack>
using namespace std;
struct rect {
int height;
int start;
};
int main() {
int caseNum;
cin >> caseNum;
for (int c = 0; c < caseNum; c++) {
int n;
cin >> n;
long long max = 0;
stack<rect> stk;
rect t;
t.height = 0;
t.start = 0;
stk.push(t);
for (int i = 0; i <= n; i++) {
rect newRect;
if (i < n) {
cin >> newRect.height;
}
else {
newRect.height = 0;
}
newRect.start = i;
while (stk.top().height > newRect.height) {
t = stk.top();
stk.pop();
long long tHeight = t.height;
long long tWidth = i - t.start;
max = tHeight * tWidth > max ? tHeight * tWidth : max;
newRect.start = t.start;
}
stk.push(newRect);
}
cout << max << endl;
}
return 0;
}