Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.004 s | 1 KBi |
#2 |
Correcto
|
0.005 s | 7 KBi |
#3 |
Correcto
|
0.004 s | 0 KBi |
#4 |
Correcto
|
0.004 s | 0 KBi |
#5 |
Correcto
|
0.004 s | 13 KBi |
#6 |
Correcto
|
0.004 s | 25 KBi |
#7 |
Correcto
|
0.006 s | 0 KBi |
#8 |
Correcto
|
0.007 s | 1 KBi |
#9 |
Correcto
|
0.005 s | 2 KBi |
#10 |
Correcto
|
0.004 s | 6 KBi |
#11 |
Correcto
|
0.004 s | 2 KBi |
#12 |
Correcto
|
0.005 s | 1 KBi |
#13 |
Correcto
|
0.004 s | 25 KBi |
#14 |
Correcto
|
0.073 s | 3 KBi |
#15 |
Correcto
|
0.058 s | 4 KBi |
#16 |
Correcto
|
0.065 s | 3 KBi |
#17 |
Correcto
|
0.062 s | 3 KBi |
#18 |
Correcto
|
0.075 s | 4 KBi |
#19 |
Correcto
|
0.044 s | 5 KBi |
#20 |
Correcto
|
0.058 s | 3 KBi |
#21 |
Correcto
|
0.057 s | 3 KBi |
#22 |
Correcto
|
0.068 s | 3 KBi |
#23 |
Correcto
|
0.08 s | 3 KBi |
#24 |
Correcto
|
0.047 s | 3 KBi |
#25 |
Correcto
|
0.053 s | 3 KBi |
#26 |
Correcto
|
0.079 s | 3 KBi |
#27 |
Correcto
|
0.048 s | 3 KBi |
#28 |
Correcto
|
0.051 s | 3 KBi |
#29 |
Correcto
|
0.062 s | 8 KBi |
/// Write by Daniel Perez .PERAPRO #include<bits/stdc++.h> using namespace std; #define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define pb push_back #define ff first #define ss second #define all(s) s.begin(), s.end() typedef long long ll; typedef unsigned long long ull; typedef long double ld; using vi=vector<int>; using vl=vector<ll>; using pii=pair<int,int>; char el = '\n'; char esp = ' '; template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } ostream& operator<<(ostream& os, const vector<int> &v){ for(auto const &i: v){ os<<i<<" "; } os<<'\n'; return os; } string yes="YES"; string no="NO"; int main(){ fast_io; /* freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); */ int n; cin>>n; vl v(n); for(int i=0;i<n;i++){ cin>>v[i]; v[i] = -v[i]; } vl right(n); vl left(n); stack<ll> st; right[n - 1] = n - 1; st.push(n - 1); for(int i =n - 2;i >=0;i--){ //int cur = st.top(); while(st.size() && v[i] >= v[st.top()]){ st.pop(); //cur = st.top(); } right[i] = (st.size() ? st.top() - 1 : n - 1); st.push(i); } while(st.size()) st.pop(); left[0] = 0; st.push(0); for(int i =1;i<n;i++){ while(st.size() && v[i] >= v[st.top()]){ st.pop(); } left[i] = (st.size() ? st.top() + 1: 0); st.push(i); } ll ans = 0; //cout<<left<<right; for(int i=0;i<n;i++){ ckmax(ans, -v[i] * ( (i - left[i] + 1) + (right[i] - i) )); } cout<<ans<<el; } /* */