Untitled
unknown
plain_text
2 years ago
960 B
3
Indexable
Never
#include <bits/stdc++.h> using namespace std; int main() { vector<int>v,t,ele,sol; string s; int ind=0; while(getline(cin, s)){ if (s.empty()) break; v.push_back(stoi(s)); t.push_back(1); ele.push_back(ind++); } for(int i=1;i<v.size();++i){ for(int j=0;j<i;++j){ if(v[i] > v[j]){ if(t[j]+1 > t[i]){ ++t[i]; ele[i] = j; } } } } int mx,d,x,mxIndx; mx = *max_element(t.begin(),t.end()); d = distance(t.begin() ,max_element(t.begin(),t.end())); x = d; mxIndx = d; cout << mx << endl << "-" << endl; for(int i=0;i<mx;++i){ x = mxIndx; sol.push_back(v[x]); mxIndx = ele[x]; } reverse(sol.begin(),sol.end()); for(int i=0;i<mx;++i){ cout <<sol[i] << endl; } return 0; }