1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <vector>
#include <cmath>
#include <cassert>
using namespace std;

const int MAXN = (1<<17) + 1;
const int MAXK = 6;

int a[MAXK][MAXN];
int d[MAXK];
int n, k;

int main() {
  assert(2 == scanf("%d%d", &n, &k));
  for (int j = 0; j < k; ++j) {
    d[j] = 0;
    for (int i = 0; i < n; ++i) {
      assert(1 == scanf("%d", &a[j][i]));
    }
  }
  for (int i = 0; i < n; ++i) {
    int jmin = 0;
    int jmax = 0;
    for (int j = 0; j < k; ++j) {
      if (a[j][i] < a[jmin][i] or (a[j][i] == a[jmin][i] and d[j] > d[jmin])) {
        jmin = j;
      }
      if (a[j][i] > a[jmax][i] or (a[j][i] == a[jmax][i] and d[j] > d[jmax])) {
        jmax = j;
      }
    }
    int x = min(a[jmax][i], max(a[jmin][i], (a[jmax][i] + a[jmin][i] + d[jmax] - d[jmin]) / 2));
    for (int j = 0; j < k; ++j) {
      d[j] += abs(a[j][i] - x);
    }
    printf("%d ", x);
  }
  printf("\n");
  /*for (int i = 0; i < k; ++i) {
    printf("%d: %d\n", i, d[i]);
  }*/
  return 0;
}