Milling machines#7714

Milling machines (Editorial)

The milling program consists of steps. Let at the -th step (1 \le i \le s) a layer of thickness m_{ij} be removed from the surface in column j~(1 \le j \le x). It is clear that the total amount removed in column will be

max(m_{1j}, m_{2j}, ..., m_{sj})

We’ll call the milling scheme the set of integers

(cuts_1, cuts_2, ..., cuts_x),

where

cuts_j = max(m_{1j}, m_{2j}, ..., m_{sj}), 1 \le j \le x

The same milling scheme is applied to all workpieces. After computing the values of cuts_j~(1 \le j \le x), this scheme is then applied sequentially to each workpiece.

Algorithm implementation

Declare the arrays. The information about the workpieces is stored in the array , and the milling scheme is stored in the array .

int detail[10001][101], cuts[101];

Read the input data.

scanf("%d %d %d %d", &w, &s, &x, &y);

Read the information about the workpieces.

for (i = 0; i < w; i++)
for (j = 0; j < x; j++)
  scanf("%d", &detail[i][j]);

Read and process the steps of the milling program. For each position , the value cuts[j] represents the maximum cutting depth achieved at any of the steps.

for (i = 0; i < s; i++)
for (j = 0; j < x; j++)
{
  scanf("%d", &val);
  if (val > cuts[j]) cuts[j] = val;
}

The maximum possible height of a workpiece is . The milling head at position is lowered to a depth of cuts[j]. Consequently, after milling, the remaining height of the -th workpiece at position will be equal to

min(detail[i][j], y - cuts[j]).
for (i = 0; i < w; i++)
{
  for (j = 0; j < x; j++)
    printf("%d ", min(detail[i][j], y - cuts[j]));
  printf("\n");
}