#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define popcount __builtin_popcount using namespace std; using namespace atcoder; typedef long long ll; typedef pair P; struct edge{ int to, cap, rev; ll cost; edge(int to, int cap, ll cost, int rev):to(to), cap(cap), cost(cost), rev(rev){} }; const int MAXV=100010; int V; vector g[MAXV]; ll h[MAXV]; ll dist[MAXV]; int prevv[MAXV], preve[MAXV]; void add_edge(int from, int to, int cap, ll cost){ edge e=edge(to, cap, cost, g[to].size()); g[from].push_back(e); e=edge(from, 0, -cost, g[from].size()-1); g[to].push_back(e); } ll min_cost_flow(int s, int t, int f){ using P=pair; const ll INF=1e18; ll res=0; fill(h, h+V, 0); while(f>0){ priority_queue, greater

> que; fill(dist, dist+V, INF); dist[s]=0; que.push({0, s}); while(!que.empty()){ P p=que.top(); que.pop(); int v=p.second; if(dist[v]0 && dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){ dist[e.to]=dist[v]+e.cost+h[v]-h[e.to]; prevv[e.to]=v; preve[e.to]=i; que.push({dist[e.to], e.to}); } } } for(int v=0; v>n>>k; V=n; ll a[100010]; for(int i=0; i>a[i]; int m; cin>>m; for(int j=0; j>b; b--; add_edge(b, i, 1, a[b]-a[i]); } } for(int i=0; i