Pagini recente » Cod sursa (job #3198943) | Cod sursa (job #531953) | Cod sursa (job #303712) | Cod sursa (job #2146770) | Cod sursa (job #2076953)
#include <fstream>
#include<stack>
#define dim 1000004
using namespace std;
stack <int> v;
int x[dim];
int main()
{
ifstream f("concurs.in");
ofstream g("concurs.out");
long long aria,Amax=0;
int i,j,N,y;
f>>N;
for(i=1;i<=N;++i)
f>>x[i];
for(i=1;i<=N;++i)
{
if(v.empty() or x[i]>x[v.top()])
{
v.push(i);
}
else if(x[i]<x[v.top()]) //avem un element de val. mai mica
{
while(!v.empty() and x[i]<x[v.top()])
{
y=v.top();
v.pop();
aria=(i-y)*x[y];
if(Amax<aria)
Amax=aria;
}
}
}
while(!v.empty() )
{
y=v.top();
v.pop();
aria=(i-y)*x[y];
if(Amax<aria)
Amax=aria;
}
g<<Amax<<'\n';
return 0;
}