Pagini recente » Cod sursa (job #2176305) | Cod sursa (job #3314686) | Cod sursa (job #834581) | Cod sursa (job #3336852) | Cod sursa (job #3354904)
#include <cstdio>
#include <cctype>
using namespace std;
const int BUF_SIZE = 65536;
char bufferIn[BUF_SIZE], bufferOut[BUF_SIZE];
int posIn = BUF_SIZE, posOut = 0;
char getChar() {
if (posIn == BUF_SIZE) {
fread(bufferIn, 1, BUF_SIZE, stdin);
posIn = 0;
}
return bufferIn[posIn++];
}
void readInt(int &x) {
x = 0; char c = getChar();
while (!isdigit(c)) c = getChar();
while (isdigit(c)) {
x = x * 10 + (c - '0');
c = getChar();
}
}
void putChar(char c) {
if (posOut == BUF_SIZE) {
fwrite(bufferOut, 1, BUF_SIZE, stdout);
posOut = 0;
}
bufferOut[posOut++] = c;
}
void writeInt(int x) {
if (x == 0) {
putChar('0');
return;
}
char s[12];
int len = 0;
while (x > 0) {
s[len++] = (x % 10) + '0';
x /= 10;
}
while (len) putChar(s[--len]);
}
int v[100001];
int dp[100001];
int previ[100001];
int cpy[100001];
int main() {
freopen("scmax.in", "r", stdin);
freopen("scmax.out", "w", stdout);
int n,pmax,vmax = -1;
readInt(n);
for(int i=1;i<=n;i++){
readInt(v[i]);
dp[i] = 1;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
if(v[i]>v[j]){
if(dp[j]+1>dp[i]){
dp[i] = dp[j]+1;
previ[i] = j;
}
}
}
if(dp[i]>vmax){
vmax = dp[i];
pmax = i;
}
}
int i = pmax;
while(i!=0){
cpy[dp[i]] = v[i];
i = previ[i];
}
writeInt(vmax);
putChar('\n');
for(int i=1;i<=vmax;i++){
writeInt(cpy[i]);
putChar(' ');
}
if (posOut > 0) {
fwrite(bufferOut, 1, posOut, stdout);
}
return 0;
}