Cod sursa(job #2977618)

Utilizator pifaDumitru Andrei Denis pifa Data 11 februarie 2023 23:53:00
Problema Cutii Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <bits/stdc++.h>

using namespace std;

ifstream in("cutii.in");
ofstream out("cutii.out");

int n, t;

struct ura
{
    int x, y, z;
};

ura v[3501];

int len[3501];

int cmp(ura a, ura b)
{
   return a.x < b.x;
}

signed main()
{
    in >> n >> t;
    while(t--)
    {
        for(int i = 1; i <= n; i++)
            in >> v[i].x >> v[i].y >> v[i].z;
        sort(v + 1, v + n + 1, cmp);
        memset(len, 0, sizeof(len));
        int lmax = 0;
        for(int i = n; i >= 1; i--)
        {
            len[i] = 1;
            for(int j = i + 1; j <= n; j++)
            {
                if(v[i].y < v[j].y && v[i].z < v[j].z && len[i] < len[j] + 1)
                {
                    len[i] = len[j] + 1;
                }
            }
            lmax = max(lmax, len[i]);
        }
        out << lmax << '\n';
    }
    return 0;
}