Cod sursa(job #1359977)

Utilizator hohoho97Valentin Nita hohoho97 Data 25 februarie 2015 10:34:20
Problema Cutii Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.29 kb
#include <fstream>

#include <vector>

#include <algorithm>

using namespace std;

bool operator< (vector<int>& v1, vector<int>& v2)
{
	return v1.front() < v2.front();
}

class Cutii
{
public:
	Cutii()
	{
		ifstream in("cutii.in");
		ofstream out("cutii.out");

		in >> n >> t;

		vals.resize(3, vector<int>(n));

		for (; t > 0; t--)
		{
			for (int i = 0; i < n; i++)
			{
				for (int j = 0; j < 3; j++)
				{
					in >> vals[j][i];
				}
			}

			sort(vals.begin(), vals.end());

			vector<int> m(n + 1);
			m[1] = 0;

			//vector<int> p(n + 1);
			//for (int i = 0; i < n + 1; i++)
			//{
			//	p[i] = i;
			//}

			int lmax = 1;
			for (int i = 1; i < n; i++)
			{
				int low = 1;
				int high = lmax;
				while (low <= high)
				{
					int mid = (low + high) / 2;
					if (vals[0][m[mid]] < vals[0][i]
						&& vals[1][m[mid]] < vals[1][i]
						&& vals[2][m[mid]] < vals[2][i])
					{
						low = mid + 1;
					}
					else
					{
						high = mid - 1;
					}
				}

				int newl = low;
				/*p[i] = m[newl - 1];*/
				m[newl] = i;

				lmax = max(lmax, newl);
			}

			out << lmax << endl;
		}

		in.close();
		out.close();
	}

private:
	int n, t;

	vector<vector<int>> vals;
};

int main()
{
	Cutii();

	return 0;
}