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
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k, m;
  cin >> n >> k >> m;
  vector<vector<int>> zelki(n, vector<int>(3));
  for (int i = 0; i < n; i++) {
    cin >> zelki[i][0] >> zelki[i][1] >> zelki[i][2];
  }
  vector<int> dp(m, INT_MAX);
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    vector<int> new_dp(m, INT_MAX);
    for (int j = 0; j < m; j++) {
      if (dp[j] != INT_MAX) {
        for (int cnt = 1; cnt <= k; cnt++) {
          int next = (j + zelki[i][1] * cnt) % m;
          new_dp[next] = min(new_dp[next], dp[j] + zelki[i][2] * cnt);
        }
      }
    }
    dp = new_dp;
  }
  for (int i = 1; i < m; i++) {
    if (dp[i] == INT_MAX) {
      cout << "-1";
    } else {
      cout << dp[i];
    }
  }
  return 0;
}