Pagini recente » Borderou de evaluare (job #1459968) | Cod sursa (job #1667834) | Cod sursa (job #1883026) | Cod sursa (job #2299947) | Cod sursa (job #2300755)
#include <iostream>
#include <fstream>
#include <set>
#include <vector>
using namespace std;
ifstream f("scmax.in");
ofstream g("scmax.out");
int n;
struct comp
{
operator()(const vector<int> &a,const vector<int> &b)
{
return a.size()>b.size();
}
};
typedef multiset<vector<int>,comp>::iterator it;
multiset<vector<int>,comp >s;
int main()
{
f>>n;
int z;
it j;
for(int i=1;i<=n;i++)
{
f>>z;
vector<int> a;
for(j=s.begin();j!=s.end() && j->back()>=z;j++);
if(j==s.end())
a.push_back(z);
else
{
a=*j;
a.push_back(z);
}
pair<it,it> k;
for(k=s.equal_range(a);k.first!=k.second;)
{
it aux;
if(k.first->back()>=z)
{
k.first++;
aux=k.first;
k.first--;
s.erase(k.first);
k.first=aux;
}
}
s.insert(a);
}
vector<int> rez=*s.begin();
g<<rez.size()<<'\n';
for(int i=0;i<rez.size();i++)
g<<rez[i]<<' ';
f.close();
g.close();
return 0;
}