Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.002 s | 0 KBi |
#2 |
Correcto
|
0.001 s | 0 KBi |
#3 |
Correcto
|
0.002 s | 0 KBi |
#4 |
Correcto
|
0.001 s | 0 KBi |
#5 |
Correcto
|
0.001 s | 0 KBi |
#6 |
Correcto
|
0.002 s | 0 KBi |
#7 |
Correcto
|
0.002 s | 0 KBi |
#8 |
Correcto
|
0.002 s | 0 KBi |
#9 |
Correcto
|
0.001 s | 0 KBi |
#10 |
Correcto
|
0.001 s | 0 KBi |
#11 |
Correcto
|
0.002 s | 0 KBi |
#12 |
Correcto
|
0.002 s | 0 KBi |
#13 |
Correcto
|
0.001 s | 0 KBi |
#14 |
Incorrecto
|
0.011 s | 1 KBi |
#15 |
Correcto
|
0.015 s | 1 KBi |
#16 |
Correcto
|
0.018 s | 1 KBi |
#17 |
Incorrecto
|
0.018 s | 1 KBi |
#18 |
Correcto
|
0.023 s | 1 KBi |
#19 |
Correcto
|
0.016 s | 1 KBi |
#20 |
Incorrecto
|
0.016 s | 1 KBi |
#21 |
Correcto
|
0.021 s | 1 KBi |
#22 |
Incorrecto
|
0.017 s | 1 KBi |
#23 |
Incorrecto
|
0.029 s | 1 KBi |
#24 |
Correcto
|
0.019 s | 1 KBi |
#25 |
Correcto
|
0.011 s | 1 KBi |
#26 |
Incorrecto
|
0.017 s | 1 KBi |
#27 |
Incorrecto
|
0.012 s | 2 KBi |
#28 |
Incorrecto
|
0.023 s | 2 KBi |
#29 |
Correcto
|
0.016 s | 1 KBi |
// Made by Daniel Diaz (@Danidiaztech) #include <bits/stdc++.h> using namespace std; #define ll long long const int mod = 1e9 + 7; const string yes = "YES", no = "NO"; void solve(){ int n; cin >> n; int a[n]; for (int i =0; i < n; i++){ cin >> a[i]; } // simulate with stack // mono-increasing stack stack<pair<int,int>> s, s2; // prev element that is less than ith int prev[n], nxt[n]; for (int i =0; i <n; i++){ while (!s.empty() && s.top().first >= a[i]){ s.pop(); } prev[i] = (s.empty() ? i : ( -s.top().second + i - 1)); s.push({a[i], i}); } for (int i = n -1; i >= 0; i--){ while (!s2.empty() && s2.top().first >= a[i]){ s2.pop(); } nxt[i] = (s2.empty() ? n - i - 1 : (s2.top().second - i - 1)); s2.push({a[i], i}); } int ans = 0; for (int i = 0; i < n; i++){ int x = (nxt[i] + prev[i] + 1) * a[i]; ans = max(ans, x); } cout << ans << '\n'; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); #if LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int tc = 1; // cin >> tc; for (int t = 1; t <= tc; t++){ solve(); } }