#include #include #include #include using namespace std; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; #define rep(i,n) for(int i=0; i<(n); i++) int main(){ int N,K; cin >> N >> K; vector A(N); vector> E(N); rep(i,N){ int c; cin >> A[i] >> c; E[i].resize(c); rep(j,c){ cin >> E[i][j]; E[i][j]--; } } const i64 maxA = 1000000000; atcoder::mcf_graph G(N+1); rep(i,N) G.add_edge(i,i+1,K,maxA); rep(i,N) for(int e : E[i]){ G.add_edge(e,i,1,maxA*(i-e)-(A[i]-A[e])); } i64 ans = G.flow(0,N,K).second; ans = maxA * N * K - ans; cout << ans << endl; return 0; } struct ios_do_not_sync { ios_do_not_sync() { ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_instance;