Cod sursa(job #2323564)

Utilizator aturcsaTurcsa Alexandru aturcsa Data 19 ianuarie 2019 12:56:07
Problema Cutii Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.46 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#define Dm 3501
using namespace std;
ifstream fin("cutii.in");
ofstream fout("cutii.out");
struct cutie
{
    int x,y,z;
};
int cmp(cutie a,cutie b)
{
    return a.x>b.x;
}
int aib[Dm][Dm];
int n,t;
cutie A[Dm];
void update(int v,int pozi,int pozj)
{
    while(pozi<=n)
    {
        while(pozj<=n)
        {
            aib[pozi][pozj]+=v;
            pozj=pozj+(pozj&(-pozj));
        }
        pozi=pozi+(pozi&(-pozi));
    }
}
int f(int pozi,int pozj)
{
    int rez=0;
    while(pozi>0)
    {
        while(pozj>0)
        {
            rez+=aib[pozi][pozj];
            pozj=pozj-(pozj&(-pozj));
        }
        pozi=pozi-(pozi&(-pozi));
    }
    return rez;
}
int main()
{
    fin>>n>>t;
    for(int nt=1; nt<=t; nt++)
    {
        for(int i=1; i<=n; i++)
            fin>>A[i].x>>A[i].y>>A[i].z;
        sort(A+1,A+n+1,cmp);
        for(int i=1;i<=n;i++)
        {
            for(int j=i;j>0;j--)
            {
                if(A[i].x>A[j].x)
                    if(A[i].y>A[j].y)
                        if(A[i].z>A[j].z)
                            update(1,A[i].y,A[i].z);
            }
        }
        int maxi=0;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(maxi<f(i,j))
                    maxi=f(i,j);
            }
        }
        fout<<maxi<<"\n";
    }
    return 0;
}