Cod sursa(job #3338418)

Utilizator parus_majorParus Major parus_major Data 3 februarie 2026 00:32:14
Problema Cutii Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>

using namespace std;

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

const int MAXN = 3502;

struct elem {
    int x, y, z;

    bool operator<(const elem& other) const {
        return x < other.x || (x == other.x && y < other.y) || (x == other.x && y == other.y && z < other.z);
    }

    bool fits(const elem& other) const {
        return x < other.x && y < other.y && z < other.z;
    }
};

int N, T;
elem v[MAXN];
int d[MAXN];

int main()
{
    fin >> N >> T;
    for (int t = 0; t < T; ++t) {
        for (int i = 0; i < N; ++i) {
            fin >> v[i].x >> v[i].y >> v[i].z;
        }
        sort(v, v + N);

        int ans = 0;
        for (int i = 0; i < N; ++i) {
            d[i] = 1;
            for (int j = 0; j < i; ++j) {
                if (v[j].fits(v[i])) {
                    d[i] = max(d[i], d[j] + 1);
                }
            }
            ans = max(ans, d[i]);
        }
        fout << ans << '\n';
    }
    return 0;
}