Pagini recente » Istoria paginii runda/1_martie_simulare_oji_2024_clasele_11_12/clasament | Cod sursa (job #2318386) | Cod sursa (job #2674884) | Cod sursa (job #2032775) | Cod sursa (job #2949355)
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int n, numbers[100005];
vector<int> s;
int main()
{
fin >> n;
for (int i = 1; i <= n; i++)
fin >> numbers[i];
// Folosim functia lower_bound pentru a gasi pozitia in vectorul s pe care ar trebui sa o ocupe i.
for (int i = 1; i <= n; i++)
{
vector<int>::iterator it = lower_bound(s.begin(), s.end(), numbers[i]);
if (it == s.end())
s.push_back(numbers[i]);
else
*it = numbers[i];
}
fout << s.size() << "\n";
int ansStack[100005], top = 0;
for (int i = n; i >= 1; i--)
{
if (numbers[i] == s.back())
{
ansStack[++top] = numbers[i];
s.pop_back();
}
}
while (top)
fout << ansStack[top--] << " ";
fout << "\n";
return 0;
}