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
76
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <deque>

#define REP(i, n) for (int i = 0; i < (n); ++i) 
#define FOR(i, a, b) for (int i = (a); i < (b); ++i) 

using namespace std;

const int MAX_N = 100100;
const int MAX_K = 7;
int n, k;
long long d[MAX_K][MAX_N];
long long res[MAX_N];

int main() {
    scanf("%d %d", &n, &k);
    REP(i, k) REP(j, n) scanf("%lld", &d[i][j]);

    k = 2;  // ;-)

    long long a = 0, b = 0;
    REP(i, n) {
        if (d[0][i] == d[1][i]) {
            res[i] = d[0][i];
            continue;
        }
        long long mid = (d[0][i] + d[1][i]) / 2;
        res[i] = mid;
        a += abs(d[0][i] - mid);
        b += abs(d[1][i] - mid);
    }

    REP(i, n) {
//        printf("%d %lld %lld\n", i, a, b);
        if (abs(a-b) <= 1) break;

        if (a < b) {
            while (abs(a-b) > 1 and res[i] < d[1][i]) {
                res[i] += 1;
                a += 1;
                b -= 1;
            }
            while (abs(a-b) > 1 and d[1][i] < res[i]) {
                res[i] -= 1;
                a += 1;
                b -= 1;
            }
        } else {
            while (abs(a-b) > 1 and res[i] < d[0][i]) {
                res[i] += 1;
                a -= 1;
                b += 1;
            }
            while (abs(a-b) > 1 and d[0][i] < res[i]) {
                res[i] -= 1;
                a -= 1;
                b += 1;
            }
        }
    }
/*
    long long va = 0, vb = 0;
    REP(i, n) {
        va += abs(d[0][i] - res[i]);
        vb += abs(d[1][i] - res[i]);
    }
    printf("%lld\n", max(va, vb));
*/
    REP(i, n) printf("%lld ", res[i]);
    printf("\n");
    return 0;
}