-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWAR.cpp
More file actions
79 lines (67 loc) · 1.44 KB
/
WAR.cpp
File metadata and controls
79 lines (67 loc) · 1.44 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
78
79
#include <iostream>
#include <stack>
#include <algorithm>
#define maxn 30004
int t;
int n;
int a[maxn];
int l[maxn];
int r[maxn];
std::stack <int> st;
void xuli()
{
for (int i = 1; i <= n; i++)
{
while(!st.empty())
{
if (a[i] <= a[st.top()]) st.pop();
else break;
}
if (st.empty()) l[i] = i;
else l[i] = i-st.top();
st.push(i);
}
while(!st.empty()) st.pop();
for (int i = n; i >= 1; i--)
{
while(!st.empty())
{
if (a[i] <= a[st.top()]) st.pop();
else break;
}
if (st.empty()) r[i] = n-i+1;
else r[i] = st.top()-i;
st.push(i);
}
while(!st.empty()) st.pop();
// for (int i = 1; i <= n; i++)
// std::cout << l[i] << " ";
// std::cout << "\n";
// for (int i = 1; i <= n; i++)
// std::cout << r[i] << " ";
// std::cout << "\n";
long long ans = 0;
int vt = 0;
for (int i = 1; i <= n; i++){
if (ans < (1ll)*(a[i]*(l[i]+r[i]-1))){
ans = (1ll)*(a[i]*(l[i]+r[i]-1));
vt = i;
}
}
std::cout << ans << " " << vt - l[vt]+1 << " " << r[vt] + vt-1 << "\n";
}
void nhap()
{
std::cin >> t;
while(t--)
{
std::cin >> n;
for (int i = 1; i <= n; i++) std:: cin >> a[i];
xuli();
}
}
int main(int argc, char const *argv[])
{
nhap();
return 0;
}