Pagini recente » Cod sursa (job #561502) | Cod sursa (job #2737802) | Borderou de evaluare (job #133721) | Cod sursa (job #278187) | Cod sursa (job #2940338)
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
using ll = long long;
using namespace std;
const int NMAX = 1e5 + 5;
/*******************************/
// INPUT / OUTPUT
ifstream f("scmax.in");
ofstream g("scmax.out");
/*******************************/
/// GLOBAL DECLARATIONS
int N, v[NMAX], dp[NMAX], pre[NMAX];
int max_len, start_sol;
vector <int> sol;
/*******************************/
/// FUNCTIONS
void ReadInput();
void Solution();
void Output();
/*******************************/
///-------------------------------------
inline void ReadInput()
{
f >> N;
for (int i = 1 ; i <= N ; ++ i)
f >> v[i];
}
///-------------------------------------
int cb(int x)
{
int st = 1, dr = max_len, pos = 0;
int mid;
while (st <= dr)
{
mid = (st + dr) / 2;
if (v[dp[mid]] < x)
{
pos = mid;
st = mid + 1;
}
else
{
dr = mid - 1;
}
}
return pos;
}
///-------------------------------------
inline void Solution()
{
int j;
for (int i = 1 ; i <= N ; ++ i)
{
j = cb(v[i]);
if (max_len < j + 1)
{
max_len = j + 1;
start_sol = i;
}
dp[j + 1] = i;
pre[i] = dp[j];
}
while (start_sol)
{
sol.push_back(start_sol);
start_sol = pre[start_sol];
}
reverse(sol.begin(), sol.end());
}
///-------------------------------------
inline void Output()
{
g << max_len << "\n";
for (auto x: sol)
g << v[x] << " ";
}
///-------------------------------------
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ReadInput();
Solution();
Output();
return 0;
}