-
Notifications
You must be signed in to change notification settings - Fork 0
/
1083 - Histogram.cpp
45 lines (41 loc) · 1 KB
/
1083 - Histogram.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<bits/stdc++.h>
#define endl '\n'
#define ll long long
#define PI 2*acos(0.0)
#define max_index 100005
using namespace std;
int main()
{
int q,t,x,n,i,area,max_area;
//freopen("output2.txt","w",stdout);
scanf("%d",&q);
t=1;
while(q--){
int time = 0;
scanf("%d",&n);
int arr[n+5];stack<int>s;
for(i=0; i<n; i++) scanf("%d",&arr[i]);
max_area = -1;
area = 0;
i=0;
while(i<n){
if(s.empty() || arr[s.top()]<=arr[i]){
s.push(i++);
}
else{
x = s.top();
s.pop();
area = arr[x]*(s.empty()?i : i-s.top()-1);
}
max_area = max(max_area,area);
}
while(!s.empty()){
x = s.top();
s.pop();
area = arr[x]*(s.empty()?i : i-s.top()-1);
max_area = max(max_area,area);
}
printf("Case %d: %d\n",t++,max_area);
}
return 0;
}