Cod sursa(job #3266817)

Utilizator Luca_georgescuLucageorgescu Luca_georgescu Data 10 ianuarie 2025 16:39:25
Problema Cutii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.41 kb
#include <bits/stdc++.h>

using namespace std;

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

struct vec
{
    int x,y,z;
}a[3505],lg[3505];

int n,t,dp[3505];
int nr;

void reset()
{
    for (int i=0; i<=n; i++ )
    {
        lg[i].x=0;
        lg[i].y=0;
        lg[i].z=0;
    }
}

bool cmp(vec a, vec b)
{
    if ( a.x!=b.x)
        return a.x<b.x;
    if ( a.y!=b.y )
        return a.y>b.y;
    return a.z>b.z;
}

void add(int q, int w)
{
    lg[q]=a[w];
}

void sclm()
{
    reset();
    add(1,1);
    nr=1;

    for (int i=2; i<=n; i++ )
    {
        if ( a[i].x>lg[nr].x && a[i].y>lg[nr].y && a[i].z>lg[nr].z )
             add(++nr,i);
        else
        {
            int st=1;
            int dr=nr;
            int poz=nr+1;
            while ( st<=dr )
            {
                int m=(st+dr)/2;
                if ( cmp(a[i],lg[m]) )
                {
                    poz=m;
                    dr=m-1;
                }
                else st=m+1;
            }
            add(poz,i);
        }
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    f.tie(NULL);
    g.tie(NULL);

    f >> n >> t;
    while ( t )
    {
        for (int i=1; i<=n; i++ )
            f >> a[i].x >> a[i].y >> a[i].z;

        sort(a+1,a+n+1,cmp);

        sclm();

        g << nr << '\n';
        t--;
    }
    return 0;
}