#include #include using namespace std; using lint = long long; #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i int main() { cin.tie(nullptr), ios::sync_with_stdio(false); int N, M, X; cin >> N >> M >> X; constexpr int C = 5; vector onset(C, vector(N + 1)), match(C, vector(N)); REP(i, N) { int c; cin >> c; onset.at(c - 1).at(i) = 1; } while (M--) { int a, b, y; cin >> a >> b >> y; match.at(b - 1).at(N - a) += y; } REP(c, C) match.at(c) = atcoder::convolution_ll(match.at(c), onset.at(c)); lint ret = 0; REP(i, N + 1) { lint tmp = i * lint(X); for (const auto &v : match) tmp += v.at(N - 1 + i); ret = max(ret, tmp); } cout << ret << endl; }