Cod sursa(job #2312543)

Utilizator Andrei-27Arhire Andrei Andrei-27 Data 4 ianuarie 2019 23:51:24
Problema Cutii Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <bits/stdc++.h>
using namespace std;

const int NR = 3501 ;
ifstream f ("cutii.in") ;
ofstream g ("cutii.out") ;
struct el
{int x, y ,z ;
}v [ NR ];
bool cmp  (  el a ,   el b )
{
        if ( a.x == b.x )
        {
             if ( a.y == b.y )  return a.z < b.z ;
             return a.y < b.y ;
        }
        return a.x < b.x ;
}
int main ()
{
    int n , t ; f >> n >> t ;
    while ( t -- )
    {
        int maxim = 1 ;
        for ( int i = 1 ; i <= n ; ++ i )   f >> v [ i ].x >> v [ i ].y >> v [ i ].z ;
        sort ( v + 1 , v + n + 1 , cmp ) ;
        vector < int > q ( n + 1 , 1 ) ;
        for ( int i = 1 ; i <  n ; ++ i )
        for ( int j = i + 1 ; j <= n ; ++ j )
        {
            if ( v [ i ].x < v [ j ].x && v [ i ].y < v [ j ].y && v [ i ].z < v [ j ].z && q [ i ] + 1 > q [ j ]  )
            {
                q [ j ] = q [ i ] + 1 ;
                if ( q [ j ] > maxim )  maxim = q [ j ] ;
            }
        }
        g << maxim << "\n" ;

    }
}