http://acm.pku.edu.cn/JudgeOnline/problem?id=1188

Код:
#include <stdio.h>
#define MAX(x, y) (((x)>(y))?(x):(y))
#define MIN(x, y) (((x)<(y))?(x):(y))
typedef struct POINT {int x; int y; int z;} pnt;

int main()
{
 int n, l, sol, i;
 pnt from, to, add;

 while(1) {
    scanf("%d",&n);
    if(n==0) break;

    scanf("%d %d %d %d",&from.x,&from.y,&from.z,&l);
    to.x = from.x+l; to.y = from.y+l; to.z = from.z+l;

    for(i=0; i<n-1; i++) {
       scanf("%d %d %d %d",&add.x,&add.y,&add.z,&l);
       from.x = MAX(add.x,from.x);
       from.y = MAX(add.y,from.y);
       from.z = MAX(add.z,from.z);
       to.x = MIN(add.x+l,to.x);  
       to.y = MIN(add.y+l,to.y);
       to.z = MIN(add.z+l,to.z);
    }
    sol = MAX((to.x - from.x) * (to.y - from.y) * (to.z - from.z), 0);
    printf("%d\n",sol);
   }
 
   return 0;
}