#include using namespace std; #define ALL(x) begin(x),end(x) #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b ostream &operator<<(ostream &os,const vector&v){ for(int i=0;i<(int)v.size();i++) os< istream &operator>>(istream &is,vector&v){ for(T &x:v)is>>x; return is; } /* multi, flowの路線で考察しています.あってますか? */ signed main(){ int N,K;cin>>N>>K; vector dp(N+1,-LINF); dp[0]=0; vector A(N); rep(i,N){ int M;cin>>A[i]>>M; chmax(dp[i+1],dp[i]); rep(_,M){ int j;cin>>j;j--; chmax(dp[i+1],dp[j]+A[i]-A[j]); } } cout<