#line 1 "/workspaces/compro/lib/template.hpp" #line 1 "/workspaces/compro/lib/Assert/Assert.hpp" #include #include #include #ifndef MY_ASSERT #define MY_ASSERT #ifdef LOCAL #define ASSERT_MSG(expr, msg) \ do { \ if (!(expr)) { \ std::cerr << msg << std::endl; \ assert(expr); \ } \ } while (0) #define FAIL ASSERT_MSG(false, "到達しない想定の場所に到達しました") #else #define ASSERT_MSG(...) (void)0 #define FAIL (void)0 #endif #endif #line 2 "/workspaces/compro/lib/io/vector.hpp" #include #ifndef IO_VECTOR #define IO_VECTOR template std::ostream &operator<<(std::ostream &out, const std::vector &v) { int size = v.size(); for (int i = 0; i < size; i++) { std::cout << v[i]; if (i != size - 1) std::cout << " "; } return out; } template std::istream &operator>>(std::istream &in, std::vector &v) { for (auto &el : v) { std::cin >> el; } return in; } #endif #line 5 "/workspaces/compro/lib/template.hpp" #include #define REP(i, n) for (int i = 0; i < (n); i++) #define FOR(i, m, n) for (int i = (m); i < (n); i++) #define RREP(i, n) for (int i = (n - 1); i >= 0; i--) #define RFOR(i, m, n) for (int i = (n - 1); i >= (m); i--) #define ALL(v) std::begin(v), std::end(v) #define coutd(n) cout << fixed << setprecision(n) #define ll long long int #define vl vector #define vi vector #define MM << " " << using namespace std; struct P { ll x; ll y; }; template void chmin(T &a, T b) { if (a > b) a = b; } template void chmax(T &a, T b) { if (a < b) a = b; } // 重複を消す。計算量はO(NlogN) template void unique(std::vector &v) { std::sort(v.begin(), v.end()); v.erase(std::unique(v.begin(), v.end()), v.end()); } #line 2 "main.cpp" // generated by oj-template v4.8.1 (https://github.com/online-judge-tools/template-generator) int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, K; cin >> N >> K; vl A(N); vi M(N); vector B(N); REP(i, N) { cin >> A[i] >> M[i]; REP(j, M[i]) { ll b; cin >> b; B[i].push_back(b); } } vector dp(N + 1, 0); REP(i, N) { dp[i + 1] = dp[i]; REP(j, M[i]) { if (A[i] - A[B[i][j] - 1] >= 0) chmax(dp[i + 1], A[i] - A[B[i][j] - 1] + dp[B[i][j] - 1]); } } cout << dp[N] << endl; }