can anyone tell me how this problem can be done? representing the unit cells with a 2d array gives me a tle.
#include <iostream>
using namespace std;
int init(long **ptr,long x1,long y1,long x2,long y2,long h)
{
int max=0;
int val;
for(int i=x1;i<x2;i++)
{
for(int j=y1;j<y2;j++)
{
val=*(*(ptr+i)+j);
max=(val>max)?val:max;
}
}
for(int i=x1;i<x2;i++)
{
for(int j=y1;j<y2;j++)
{
*(*(ptr+i)+j)=(max+h);
}
}
return (max+h);
}
int main()
{
long d,s,n;
cin >> d;
cin >> s;
cin >> n;
long max=0;
long **ptr=new long*[d];
for(long i=0;i<d;i++)
{
*(ptr+i)=new long[s];
for(long j=0;j<s;j++)
{
*(*(ptr+i)+j)=0;
}
}
int l,b,w,x,y,temp;
for(long i=0;i<n;i++)
{
cin >> l;
cin >> b;
cin >> w;
cin >> x;
cin >> y;
temp=init(ptr,x,y,x+l,y+b,w);
max=(temp>max)?temp:max;
}
cout << max;
return 0;
}