Pagini recente » Cod sursa (job #2771844) | Cod sursa (job #2564369) | Cod sursa (job #2807383) | Cod sursa (job #3302564) | Cod sursa (job #2857111)
#include <fstream>
using namespace std;
ifstream fin("scmax.in");
ofstream fout("scmax.out");
int n, a[100001], lmax;
int dp[100001];
int main()
{
fin >> n;
for(int i=1; i<=n; i++)
fin >> a[i];
lmax = 1;
dp[1] = a[1];
for(int i=2; i<=n; i++){
if(a[i] < dp[lmax])
dp[lmax] = a[i];
else
if(a[i] > dp[lmax]){
lmax++;
dp[lmax] = a[i];
}
}
fout << lmax << '\n';
for(int i=1; i<=lmax; i++)
fout << dp[i] << ' ';
return 0;
}