Cod sursa(job #1680108)

Utilizator Player1Player 1 Player1 Data 8 aprilie 2016 15:21:35
Problema Subsir crescator maximal Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 1.42 kb
#include <stdio.h>
#include <vector>
#define NMIN 2000000003

using namespace std;

int main(){
	freopen("scmax.in", "r", stdin);
	freopen("scmax.out","w", stdout);
	int n, i, j, max, min, indexMax, indexMin, biggestMin, indexBig;
	vector<int> nums;
	scanf("%d ", &n);
	for(i = 0; i < n; i++)
		scanf("%d ", &nums[i]);
	vector<vector<int>> solutions;
	vector<int> temp(1,nums[0]);
	solutions.push_back(temp);
	for(i = 1; i < nums.size(); i++){
		max = 0;
		min = NMIN;
		biggestMin = 0;
		for(j = 0; j < solutions.size(); j++){
			if(solutions[j][solutions[j].size() - 1] > max){
				max = solutions[j][solutions[j] - size() - 1];
				indexMax = j;
			}
			if(solutions[j][solutions[j].size() - 1] < min){
				min = solutions[j][solutions[j] - size() - 1];
				indexMin = j;
			}
			if(([solutions[j].size() - 1] > biggestMin) && ([solutions[j].size() - 1] < nums[i])){
				biggestMin = solutions[j].size();
				indexBig = j;
			}
		}
		if(nums[i] > max)
			solutions[indexMax].push_back(nums[i]);
		if(nums[i] < min){
			temp[0] = nums[i];
			solutions.push_back(temp);
		}
		if((nums[i] > min) && (nums[i] < max) && (biggestMin !=0)){
			for(j = 0; j < solutions[indexBig].size())
				solutions[indexBig+1][j] = solutions[indexBig][j];
			solutions[indexBig+1].push_back(nums[i]);
		}
	}
	for(int i = 0; i < solutions[solutions.size() - 1].size();i++)
		prinf("%d ", solutions[solutions.size() - 1][i]);
}