Pagini recente » Cod sursa (job #3240684) | Cod sursa (job #399816) | Cod sursa (job #2436248) | Cod sursa (job #2210335) | Cod sursa (job #3186748)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin("cutii.in");
ofstream cout("cutii.out");
int n,t,i,d[3502];
struct cub{
int x,y,z;
}c[3502];
bool cmp(cub a,cub b){
if(a.x==b.x){
if(a.y==b.y)
return a.z>b.z;
return a.y>a.y;
}
return a.x<b.x;
}
bool verif(int i,int j){
return c[i].y>c[j].y&&c[i].z>c[j].z;
}
void sclm(int& k){
for(int i=1;i<=n;i++){
if(k==0||verif(i,d[k]))
d[++k]=i;
else{
int st=1,dr=k,poz=0;
while(st<=dr){
int mid=(st+dr)/2;
if(verif(i,d[mid])){
st=mid+1;
}else{
dr=mid-1;
if(c[d[mid]].y==c[i].y){
if(c[d[mid]].z>c[i].z)
poz=mid;
}else
if(c[d[mid]].z==c[i].z){
if(c[d[mid]].y>c[i].y)
poz=mid;
}else
poz=mid;
}
}
if(poz!=0)
d[poz]=i;
else
d[++k]=i;
}
}
}
int main()
{
cin>>n>>t;
while(t--){
for(i=1;i<=n;i++)
cin>>c[i].x>>c[i].y>>c[i].z;
sort(c+1,c+n+1,cmp);
int k=0;
sclm(k);
cout<<k<<'\n';
}
return 0;
}