-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlightoj 1083.cpp
More file actions
77 lines (68 loc) · 1.35 KB
/
Copy pathlightoj 1083.cpp
File metadata and controls
77 lines (68 loc) · 1.35 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include<bits/stdc++.h>
using namespace std;
#define mx 1000005
#define ll long long
void IO()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
}
int ar[mx];
int pre[mx],suf[mx];
int m,n,k,ii,dek;
void solve()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&ar[i]),pre[i]=0,suf[i]=0;
stack<pair<int,int>>s;
for(int i=1;i<=n;i++)
{
if(s.empty())
{
s.push({ar[i],i});
continue;
}
while(!s.empty() && s.top().first>=ar[i])
{
pre[i]+=pre[s.top().second]+1;
s.pop();
}
s.push({ar[i],i});
}
while(!s.empty())s.pop();
for(int i=n;i>=1;i--)
{
if(s.empty())
{
s.push({ar[i],i});
continue;
}
while(!s.empty() && s.top().first>=ar[i])
{
suf[i]+=suf[s.top().second]+1;
s.pop();
}
s.push({ar[i],i});
}
int re=0;
for(int i=1;i<=n;i++)
{
int val=pre[i]+suf[i]+1;
// cout<<pre[i]<<" "<<suf[i]<<" "<<ar[i]<<endl;
re=max(re,val*ar[i]);
}
printf("Case %d: %d\n",++ii,re );
}
int main()
{
IO();
int t=1;
scanf("%d",&t);
while(t--)
{
solve();
}
return 0;
}