Cod sursa(job #1770136)

Utilizator preda.andreiPreda Andrei preda.andrei Data 3 octombrie 2016 19:54:53
Problema Cutii Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.39 kb
#include <algorithm>
#include <fstream>
#include <tuple>
#include <vector>

using namespace std;

typedef tuple<int, int, int> Cutie;

bool CmpCutii(const Cutie &a, const Cutie &b)
{
    return get<0>(a) > get<0>(b);
}

bool Incape(const Cutie &ma, const Cutie &mi)
{
    return get<1>(ma) > get<1>(mi) && get<2>(ma) > get<2>(mi);
}

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

    int n, t;
    fin >> n >> t;

    vector<Cutie> cutii(n + 1);
    vector<int> lmax(n + 1);
    vector<vector<int>> pozitii(n + 1);

    while (t--) {
        for (int i = 1; i <= n; ++i)
            fin >> get<0>(cutii[i]) >> get<1>(cutii[i]) >> get<2>(cutii[i]);
        sort(cutii.begin() + 1, cutii.end(), CmpCutii);

        fill(lmax.begin() + 1, lmax.end(), 1);
        fill(pozitii.begin() + 1, pozitii.end(), vector<int>());
        int rezultat = 0;

        for (int i = 1; i <= n; ++i) {
            for (int j = rezultat; j > 0 && lmax[i] == 1; --j) {
                for (int poz : pozitii[j]) {
                    if (Incape(cutii[poz], cutii[i])) {
                        lmax[i] = j + 1;
                        break;
                    }
                }
            }

            pozitii[lmax[i]].push_back(i);
            rezultat = max(rezultat, lmax[i]);
        }

        fout << rezultat << "\n";
    }

    return 0;
}