Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.004 s | 8 KBi |
#2 |
Correcto
|
0.006 s | 0 KBi |
#3 |
Correcto
|
0.004 s | 0 KBi |
#4 |
Correcto
|
0.005 s | 4 KBi |
#5 |
Correcto
|
0.004 s | 4 KBi |
#6 |
Correcto
|
0.004 s | 0 KBi |
#7 |
Correcto
|
0.003 s | 24 KBi |
#8 |
Correcto
|
0.004 s | 1 KBi |
#9 |
Correcto
|
0.004 s | 0 KBi |
#10 |
Correcto
|
0.005 s | 1 KBi |
#11 |
Correcto
|
0.006 s | 0 KBi |
#12 |
Correcto
|
0.004 s | 2 KBi |
#13 |
Correcto
|
0.005 s | 6 KBi |
#14 |
Correcto
|
0.056 s | 5 KBi |
#15 |
Correcto
|
0.045 s | 3 KBi |
#16 |
Correcto
|
0.054 s | 15 KBi |
#17 |
Correcto
|
0.061 s | 1 KBi |
#18 |
Correcto
|
0.034 s | 1 KBi |
#19 |
Correcto
|
0.069 s | 1 KBi |
#20 |
Correcto
|
0.089 s | 1 KBi |
#21 |
Correcto
|
0.056 s | 1 KBi |
#22 |
Correcto
|
0.078 s | 2 KBi |
#23 |
Correcto
|
0.076 s | 1 KBi |
#24 |
Correcto
|
0.056 s | 20 KBi |
#25 |
Correcto
|
0.045 s | 1 KBi |
#26 |
Correcto
|
0.074 s | 1 KBi |
#27 |
Correcto
|
0.068 s | 1 KBi |
#28 |
Correcto
|
0.068 s | 3 KBi |
#29 |
Correcto
|
0.089 s | 7 KBi |
#include <iostream> #include <vector> #include <stack> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } a.push_back(0); n++; stack<int> s; int64_t best = 0; for (int i = 0; i < n; ++i) { while (s.size() > 0 and a[s.top()] > a[i]) { int middle = s.top(); int64_t height = a[middle]; s.pop(); int left = s.size() > 0 ? s.top() : -1; // index of first element to the left of middle that is strictly smaller int right = i; // index of first element to the right of middle that is strictly smaller int64_t width = right - left - 1; best = max(best, height * width); } s.push(i); } cout << best << endl; return 0; }