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
#include <bits/stdc++.h>
#define dbg(x) " [" << #x << ": " << (x) << "] "
using namespace std;
using ll = long long;
template<typename A, typename B>
ostream& operator<<(ostream& out, const pair<A,B>& p) {
    return out << "(" << p.first << ", " << p.second << ")";
}
template<typename T>
ostream& operator<<(ostream& out, const vector<T>& c) {
    out << "{";
    for(auto it = c.begin(); it != c.end(); it++) {
        if(it != c.begin()) out << ", ";
        out << *it;
    }
    return out << "}";
}

const int N = 7000;

ll dp[N];
ll nw_dp[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, k, m;
    cin >> n >> k >> m;
    vector<vector<pair<int, ll>>> v(k);
    for(int i = 0; i < n; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        v[a].push_back({b, c});
    }

    for(int i = 1; i < m; i++) dp[i] = 1e18;
    for(int i = 0; i < k; i++) {
        for(int j = 0; j < m; j++) nw_dp[j] = 1e18;
        for(auto [ms, w] : v[i]) {
            for(int x = 0; x < m; x++) {
                int id = x + ms;
                if(id >= m) id -= m;
                nw_dp[id] = min(nw_dp[id], w + dp[x]);
            }
        }
        for(int j = 0; j < m; j++) dp[j] = nw_dp[j];
    }
    dp[0] = 0;

    int pw = 1;
    while(pw < m) {
        for(int i = 0; i < m; i++) nw_dp[i] = 1e18;
        for(int i = 0; i < m; i++) {
            for(int j = 0; j < m; j++) {
                int id = i + j;
                if(id >= m) id -= m;
                nw_dp[id] = min(nw_dp[id], dp[i] + dp[j]);
            }
        }
        for(int i = 0; i < m; i++) dp[i] = nw_dp[i];
        pw *= 2;
    }

    for(int i = 0; i < m; i++) {
        if(dp[i] == 1e18) cout << -1 << '\n';
        else cout << dp[i] << '\n';
    }

    return 0;
}