Pagini recente » Cod sursa (job #531073) | Cod sursa (job #2650097) | Cod sursa (job #1556904) | Cod sursa (job #844711) | Cod sursa (job #584990)
Cod sursa(job #584990)
#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 {
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;
}