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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Gdybym mial wiecej czasu, to moze jakiegoś lp_solve'a bym napisal...
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#define PB push_back
#define MP make_pair
using namespace std;
const int N = 1e5 + 5;
long long cia[10][N];
long long res[N];

typedef long long ll;
bool is_mid(int c, int i) {
  int x;
  if (c == 3) {
    x = 2;
  } else {
    x = 3;
  }
  return 1ll * (cia[c][i] - cia[x][i]) * (cia[c][i] - cia[6 - c - x][i]) <= 0;
}
ll dis[10];
int main() {
  ios_base::sync_with_stdio(0);
  int n, k;
  cin>>n>>k;
  k = min(k, 3);
  for (int c = 1; c <= 3; c++) {
    for (int i = 1; i <= n; i++) {
      if (c <= k) {
        cin>>cia[c][i];
      } else {
        cia[c][i] = cia[c - 1][i];
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int c = 1; c <= 3; c++) {
      if (is_mid(c, i)) {
        res[i] = cia[c][i];
      }
    }
    for (int c = 1; c <= 3; c++) {
      dis[c] += abs(cia[c][i] - res[i]);
    }
  }
  vector<pair<long long, long long> > nico;
  for (int c = 1; c <= 3; c++) {
    nico.PB(MP(dis[c], c));
  }
  sort(nico.begin(), nico.end());
  int where_max = nico[2].second;
  ll to_change = (nico[2].first - nico[1].first) / 2;
  for (int i = 1; i <= n; i++) {
    if (res[i] != cia[where_max][i]) {
      long long diff = cia[where_max][i] - res[i];
      long long to_change_here = min(to_change, abs(diff));
      to_change -= to_change_here;
      res[i] += to_change_here * (diff) / abs(diff);
    }
    if (to_change == 0) {
      break;
    }
  }
  for (int i = 1; i <= n; i++) {
    cout<<res[i]<<" ";
  }
  cout<<endl;
  return 0;
}