Cod sursa(job #3267290)

Utilizator Luca_georgescuLucageorgescu Luca_georgescu Data 11 ianuarie 2025 10:45:41
Problema Cutii Scor 40
Compilator cpp-64 Status done
Runda cex_7 Marime 1.09 kb
#include <bits/stdc++.h>
#define int long long

using namespace std;

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

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

int n,t,dp[3505];

void reset()
{
    for (int i=0; i<=n; i++ )
        dp[i]=0;
}

bool cmp(vec a, vec b)
{
    if ( a.x>b.x || a.x<b.x )
        return a.x<b.x;

    if ( a.y>b.y || a.y<b.y )
        return a.y<b.y;
    else
        return a.z<b.z;


}

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;

        int maxi=0;
        sort(a+1,a+n+1,cmp);

        reset();

        for (int i=1; i<=n; i++ )
        {
            dp[i]=1;
            for (int j=1; j<i; j++ )
            {
                if ( a[i].x>a[j].x && a[i].y>a[j].y && a[i].z>a[j].z )
                    dp[i]=max(dp[i],dp[j]+1);
                maxi=max(maxi,dp[i]);
            }
        }
        g << maxi << '\n';
        t--;
    }
    return 0;
}