#include using namespace std; #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i,n) for (int i = 0; i < (n); ++i) typedef long long ll; typedef unsigned long long ull; using P=pair; const ll INF=1e9; const int mod=1e9+7; void solve(){ int n,k; cin>>n>>k; vectordp(n); vectora(n); ll ans=0; rep(i,n){ int m; cin>>a[i]>>m; rep(j,m){ int b; cin>>b; b--; if(i){chmax(dp[i],dp[i-1]);} chmax(dp[i],dp[b]+a[i]-a[b]); } } cout<