Pagini recente » Cod sursa (job #1939451) | Cod sursa (job #752523) | Cod sursa (job #2465568) | Cod sursa (job #1772410) | Cod sursa (job #1770781)
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: main.cpp
* Author: octavian
*
* Created on 04 October 2016, 18:10
*/
#include <cstdlib>
#include <cstdio>
using namespace std;
const int NMAX = 100005;
int best[NMAX];
int bSearchLarger(int start, int end, int x) {
int pos = 0;
int pow = 1;
while((pow << 1) <= end) {
pow <<= 1;
}
while(pow > 0) {
if(x > best[pos + pow]) {
pos += pow;
}
pow >>= 1;
}
return pos + 1;
}
/*
*
*/
int main(int argc, char** argv) {
FILE *fin = fopen("scmax.in", "r");
FILE *fout = fopen("scmax.out", "w");
int N;
fscanf(fin, "%d", &N);
for(int i = 1 ; i <= N ; i++) {
int x;
fscanf(fin, "%d", &x);
if(x > best[best[0]]) {
best[++best[0]] = x;
}
else {
int smallestLarger = bSearchLarger(1, best[0], x);
// fprintf(fout, "smallestLarger: %d\n", smallestLarger);
best[smallestLarger] = x;
}
}
fprintf(fout, "%d\n", best[0]);
for(int i = 1 ; i <= best[0] ; i++) {
fprintf(fout, "%d ", best[i]);
}
fclose(fin);
fclose(fout);
return 0;
}