Pagini recente » Cod sursa (job #3267906) | Cod sursa (job #248988) | Cod sursa (job #677954) | Cod sursa (job #1072118) | Cod sursa (job #584994)
Cod sursa(job #584994)
#include <queue>
#include <fstream>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
struct element {
long long h;
int ant;
};
struct compara_ant {
bool operator() (const element& a,const element& b) const {
if (a.ant==b.ant) return (a.h > b.h);
else
return (a.ant < b.ant);
}
};
priority_queue<element, vector<element>, compara_ant> q;
int n,i,j,x,nrv;
element e,a[100000];
int main () {
f >> n;e.h=e.ant=0;q.push(e);
for (i=1;i<=n;i++) {
f >> x;
nrv=-1;e.h=2000000001;
while (e.h>=x && q.empty()==false) {
nrv++;a[nrv]=e;
e=q.top();q.pop();
}
q.push(e);
e.ant=e.ant+1;e.h=x;q.push(e);
for (j=1;j<=nrv;j++) q.push(a[j]);
}
e=q.top();
g << e.ant << '\n';
f.close();g.close();
return 0;
}