Problem:
Taxi
PCK Taxi in Aizu city, owned by PCK company, has adopted a unique billing system: the user can decide the taxi fare. Today as usual, many people are waiting in a queue at the taxi stand in front of the station.
In front of the station, there are $N$ parking spaces in row for PCK taxis, each with an index running from $1$ to $N$. Each of the parking areas is occupied by a taxi, and a queue of potential passengers is waiting for the ride. Each one in the queue has his/her own plan for how much to pay for the ride.
To increase the company’s gain, the taxi driver is given the right to select the passenger who offers the highest taxi fare, rejecting others.
The driver in the $i$-th parking space can perform the following actions any number of times in any sequence before he finally selects a passenger and starts driving.
Offer a ride to the passenger who is at the head of the $i$-th parking space’s queue.
Reject to offer a ride to the passenger who is at the head of the $i$-th parking space’s queue. The passenger is removed from the queue.
Move to the $i + 1$-th parking area if it is empty. If he is in the $N$-th parking area, he leaves the taxi stand to cruise the open road.
A preliminary listening is made as to the fare the users offer. Your task is to maximize the sales volume of PCK Taxi in reference to the table of offered fares. A taxi cannot accommodate more than one passenger.
Given the number of taxi parking spaces and information regarding the persons waiting in the parking areas, calculate the maximum possible volume of sales.
Input
The input is given in the following format.
$N$
$s_1$
$s_2$
$...$
$s_N$
The first line provides the number of taxi parking areas $N$ ($1 \leq N \leq 300,000$). Each of the subsequent $N$ lines provides information on the customers queueing in the $i$-th taxi parking area in the following format:
$M$ $c_1$ $c_2$ ... $c_M$
The first integer $M$ ($1 \leq M \leq 300,000$) indicates the number of customers in the queue, and the subsequent array of integers $c_j$ ($1 \leq c_j \leq 10,000$) indicates the fare the $j$-th customer in the queue is willing to pay. The total number of customers in the taxi stand is equal to or less than $300,000$.
Output
Output the maximum volume of sales.
Sample Input
3
3 8 10 1
4 7 1 2 15
3 11 8 19
Sample Output
45

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(void){
	long long n,m,c,i,j,sum=0;
	priority_queue<int,vector<int>,greater<int>> que;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>m;
		for(j=0;j<m;j++){
			cin>>c;
			que.push(c);
			if(j!=0) que.pop();
		}
	}
	for(i=0;i<n;i++){
		sum+=que.top();
		que.pop();
	}
	cout<<sum<<endl;
	return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 5164
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int N;
    cin>>N;
    multiset<int> s;
    for(int i=1;i<=N;i++){
        int n;
        cin>>n;
        vector<int> C(n);
        for(int j=0;j<n;j++) cin>>C[j];
        sort(C.rbegin(),C.rend());
        s.insert(C[0]);
        int nd = 1;
        while(nd != C.size() && *s.begin() < C[nd]){
            s.insert(C[nd]);
            nd++;
            int a = *s.begin();
            s.erase(s.find(a));
        }
    }
    int ans = 0;
    for(int x:s) ans += x;
    cout<<ans<<endl;
}
accuracy: 1
time_ms: 130
memory_kb: 17372
final_rank: 13

code_snippet: #include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); --i)

#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)

using namespace std;

using ll = long long;
using PLL = pair<ll, ll>;

template<class T, class U> bool chmin(T& a, const U& b) { return a > b ? a = b, true : false; }
template<class T, class U> bool chmax(T& a, const U& b) { return a < b ? a = b, true : false; }

constexpr int MOD = 1000000007;

int main() {
    int N; scanf("%d", &N);
    vector<vector<int>> A(N);
    rep (i, N) {
        int M; scanf("%d", &M);
        A[i].resize(M);
        for (int& a : A[i]) scanf("%d", &a);
    }
    priority_queue<int> que;
    ll ans = 0;
    rrep (i, N) {
        for (auto a : A[i]) que.push(a);
        if (!que.empty()) {
            ans += que.top(); que.pop();
        }
    }
    printf("%lld\n", ans);
}
accuracy: 1
time_ms: 40
memory_kb: 19208
final_rank: 6

code_snippet: #include <iostream>
#include <queue>
#include <vector>
using namespace std;
using ll = long long;
int main() {
	int N;cin >> N;
	vector<vector<ll>> C(N);
	for (int i = 0;i < N;i++) {
		int m;cin >> m;
		for (int j = 0;j < m;j++) {
			ll x;cin >> x;C[i].push_back(x);
		}
	}
	priority_queue<ll> pq;
	ll res = 0;
	for (int i = N-1;i >= 0;i--) {
		for (auto v : C[i]) pq.push(v);
		res += pq.top();
		pq.pop();
	}
	cout << res << endl;
}
accuracy: 1
time_ms: 60
memory_kb: 19780
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i)
#define all(a) (a).begin(),(a).end()

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    
    int N;
    cin >> N;
    
    vector<vector<int>> C(N);
    rep(i, 0, N) {
        int M;
        cin >> M;
        rep(j, 0, M) {
            int c;
            cin >> c;
            C[i].push_back(c);
        }
    }
    
    reverse(all(C));
    
    priority_queue<int> que;
    ll ans = 0;
    rep(i, 0, N) {
        for (int c : C[i]) que.push(c);
        ans += que.top();
        que.pop();
    }
    cout << ans << '\n';
}
accuracy: 1
time_ms: 40
memory_kb: 19384
final_rank: 7

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using pii = pair<int, int>;
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return true;} return false;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return true;} return false;}
constexpr int INF = 1e9;
constexpr ll Mod = 1'000'000'007;
#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <class S, S (*op)(S, S), S (*e)(), class F, S (*mapping)(F, S),
          F (*composition)(F, F), F (*id)()>
struct lazysegtree {
  private:
    int n, lg2, sz;
    std::vector<S> d;
    std::vector<F> lz;

    void update(int i) {
        d[i] = op(d[2 * i], d[2 * i + 1]);
    }

    void all_apply(int i, F f) {
        d[i] = mapping(f, d[i]);
        if (i < sz) lz[i] = composition(f, lz[i]);
    }

    void push(int i) {
        all_apply(2 * i, lz[i]);
        all_apply(2 * i + 1, lz[i]);
        lz[i] = id();
    }

  public:
    lazysegtree(int _n) : lazysegtree(std::vector<S>(_n, e())) {}

    lazysegtree(const std::vector<S> &v) : n(v.size()) {
        lg2 = 0;
        while ((1 << lg2) < n) lg2++;
        sz = 1 << lg2;
        d = std::vector<S>(2 * sz, e());
        lz = std::vector<F>(2 * sz, id());
        for (int i = 0; i < n; i++) d[sz + i] = v[i];
        for (int i = sz - 1; i >= 1; i--) update(i);
    }

    void set(int p, S x) {
        assert(0 <= p && p < n);
        p += sz;
        rrep(i, 1, lg2 + 1) push(p >> i);
        d[p] = x;
        rep(i, 1, lg2 + 1) update(p >> i);
    }

    S get(int p) {
        assert(0 <= p && p < n);
        p += sz;
        rrep(i, 1, lg2 + 1) push(p >> i);
        return d[p];
    }

    S prod(int l, int r) {
        assert(0 <= l && l <= r && r <= n);
        if (l == r) return e();
        l += sz;
        r += sz;
        rrep(i, 1, lg2 + 1) {
            if (((l >> i) << i) != l) push(l >> i);
            if (((r >> i) << i) != r) push((r - 1) >> i);
        }

        S sml = e(), smr = e();
        while (l < r) {
            if (l & 1) sml = op(sml, d[l++]);
            if (r & 1) smr = op(d[--r], smr);
            l >>= 1;
            r >>= 1;
        }

        return op(sml, smr);
    }

    S all_prod() {
        return d[1];
    }

    void apply(int p, F f) {
        assert(0 <= p && p < n);
        p += sz;
        rrep(i, 1, lg2 + 1) push(p >> i);
        d[p] = mapping(f, d[p]);
        rep(i, 1, lg2 + 1) update(p >> i);
    }

    void apply(int l, int r, F f) {
        assert(0 <= l && l <= r && r <= n);
        if (l == r) return;
        l += sz;
        r += sz;
        rrep(i, 1, lg2 + 1) {
            if (((l >> i) << i) != l) push(l >> i);
            if (((r >> i) << i) != r) push((r - 1) >> i);
        }

        {
            int l2 = l, r2 = r;
            while (l < r) {
                if (l & 1) all_apply(l++, f);
                if (r & 1) all_apply(--r, f);
                l >>= 1;
                r >>= 1;
            }
            l = l2;
            r = r2;
        }

        rep(i, 1, lg2 + 1) {
            if (((l >> i) << i) != l) update(l >> i);
            if (((r >> i) << i) != r) update((r - 1) >> i);
        }
    }

    template <class G> int max_right(int l, G g) {
        assert(0 <= l && l <= n);
        assert(g(e()));
        if (l == n) return n;
        l += sz;
        for (int i = lg2; i >= 1; i--) push(l >> i);
        S sm = e();
        do {
            while (l % 2 == 0) l >>= 1;
            if (!g(op(sm, d[l]))) {
                while (l < sz) {
                    push(l);
                    l = (2 * l);
                    if (g(op(sm, d[l]))) {
                        sm = op(sm, d[l]);
                        l++;
                    }
                }
                return l - sz;
            }
            sm = op(sm, d[l]);
            l++;
        } while ((l & -l) != l);
        return n;
    }

    template <class G> int min_left(int r, G g) {
        assert(0 <= r && r <= n);
        assert(g(e()));
        if (r == 0) return 0;
        r += sz;
        for (int i = lg2; i >= 1; i--) push((r - 1) >> i);
        S sm = e();
        do {
            r--;
            while (r > 1 && (r % 2)) r >>= 1;
            if (!g(op(d[r], sm))) {
                while (r < sz) {
                    push(r);
                    r = (2 * r + 1);
                    if (g(op(d[r], sm))) {
                        sm = op(d[r], sm);
                        r--;
                    }
                }
                return r + 1 - sz;
            }
            sm = op(d[r], sm);
        } while ((r & -r) != r);
        return 0;
    }
};

using S = int;
using F = int;
S op(S a, S b){ return max(a, b); }
S e(){ return -INF; }
S mapping(F f, S x){ return x+f; }
F composition(F f, F g){ return f+g; }
F id(){ return 0; }

int main() {
    int N; cin >> N;
    vi M(N);
    vector<priority_queue<int>> c(N);
    for (int i = 0; i < N; i++) {
        cin >> M[i];
        for (int j = 0; j < M[i]; j++) {
            int C; cin >> C;
            c[i].push(C);
        }
    }
    lazysegtree<S, op, e, F, mapping, composition, id> Seg(N);
    for (int i = 0; i < N; i++) Seg.set(i, -(i+1));
    priority_queue<pii> Q;
    for (int i = 0; i < N; i++) {
        if (!c[i].empty()) {
            Q.push({c[i].top(), i});
            c[i].pop();
        }
    }
    ll ans = 0;
    int cnt = 0;
    while (!Q.empty() && cnt != N) {
        int A = Q.top().first, B = Q.top().second;
        Q.pop();
        if (Seg.prod(B, N) != 0) {
            cnt++;
            ans += A;
            Seg.apply(B, N, 1);
            if (!c[B].empty()) {
                Q.push({c[B].top(), B});
                c[B].pop();
            }
        }
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 200
memory_kb: 39012
final_rank: 17

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(ll i=0;i<(ll)N;i++)
#define all(X) X.begin(),X.end()
#define pb push_back
template<typename T>
class RSQ {//一点更新区間sum
    public:
    ll size=1;
    vector<T>dataS;

    void init(int N){
        while(size<=N)size=size*2;
        dataS.assign(size*2,0);
    }

    void update(int p,T x){
        p=p+size;
        dataS[p]=x;
        while(p>1){
            p>>=1;
            dataS[p]=dataS[p*2]+dataS[p*2+1];
        }
    }

    T ISum(int l,int r,int a,int b,int u){
        if(r<=a||b<=l)return 0;
        if(l<=a&&b<=r)return dataS[u];
        int m=(a+b)>>1;
        T L=ISum(l,r,a,m,u*2);
        T R=ISum(l,r,m,b,u*2+1);
        return L+R;
    }
    T Sum(int l,int r){return ISum(l,r,0,size,1);}
};

int main(){
    int N;cin>>N;
    priority_queue<pair<ll,ll>>Q;
    rep(i,N){
        int M;cin>>M;
        rep(j,M){
            ll x;cin>>x;
            Q.push({x,i});
        }
    }
    RSQ <ll>seg;
    seg.init(N);
    ll ans = 0;
    int ct = 0;
    set<ll>rest={-1,N};
    rep(i,N)rest.insert(i);
    while(!Q.empty()&&ct<N){
        auto [x,i]=Q.top();
        Q.pop();
        if(seg.Sum(0,i+1)<i+1){
            ans += x;
            auto it = rest.lower_bound(i);
            if(*it>i)it--;
            ll v = *it;
            if(v==-1||v==N)continue;
            rest.erase(v);
            seg.update(v,1);
        }
    }
    cout<<ans<<endl;
}
accuracy: 1
time_ms: 240
memory_kb: 31420
final_rank: 16

code_snippet: #include <bits/stdc++.h>
#include <iomanip>
#include <numbers>
#include <cassert>
#include <numeric>
#ifdef _MSC_VER
#include <intrin.h>
#endif
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pint = pair<int, int>;
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
template<typename T>
bool chmax(T & a, const T & b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T & a, const T & b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9;
const ll linf = 1e18;
const int dy[] = { 0,0,1,-1 }, dx[] = { 1,-1,0,0 };
int main() {
    int n; cin >> n;
    vector<vector<int>> c(n);
    rep(i, n) {
        int m; cin >> m;
        c[i].resize(m);
        rep(j, m) cin >> c[i][j];
    }
    reverse(c.begin(), c.end());
    ll ans = 0;
    multiset<int> st;
    rep(i, n) {
        rep(j, c[i].size()) st.insert(c[i][j]);
        ans += *st.rbegin();
        st.erase(prev(st.end()));
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 90
memory_kb: 19780
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */



int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	LL N; cin >> N;
	VVL cs(N);
	FOR(i, 0, N) {
		int M; cin >> M;
		FOR(j, 0, M) {
			LL c; cin >> c;
			cs[i].push_back(c);
		}
	}

	LL ans = 0;
	priority_queue<LL>pq;
	FORR(i, N - 1, 0 - 1) {
		FOR(j, 0, SZ(cs[i])) {
			pq.push(cs[i][j]);
		}
		ans += pq.top();
		pq.pop();
	}
	cout << ans << endl;

	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 19472
final_rank: 5

code_snippet: #ifdef GOHACHI
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
template<class T> using VC = vector<T>;
template<class T,class TT> using P = pair<T,TT>;
template<class T,class TT,class TTT> using TP = tuple<T,TT,TTT>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> using pqR = priority_queue<T>;
#define F first
#define S second
#define INF LLONG_MAX
#define MOD 998244353
ll DX[4] = { 0 , 1 , 0 , -1 };
ll DY[4] = { -1 , 0 , 1 , 0 };
#define st(x,y) sort(x,x+y)
#define stR(x,y) sort(x,x+y,greater<ll>())
#define ST(x) sort(x.begin(),x.end())
#define STR(x) sort(x.rbegin(),x.rend())
#define rep(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define repR(i,a,b) for(ll i=(ll)(a);i>=(ll)(b);i--)
#define rev(x,y) reverse(x,x+y)
#define REV(x) reverse(x.begin(),x.end())
#define dec(x) fixed << setprecision(x)
#define POW(x,y) (ll)pow(x,y)
ll s;
void solve() {
	ll n; cin>>n;
	pq<ll> pq;
	rep(t,1,n+1) {
		ll m; cin>>m;
		ll c;
		rep(i,0,m) { cin>>c;
			pq.push(c);
			if (i!=0) pq.pop();
		}
	}
	rep(t,0,n) { s+=pq.top(); pq.pop(); }
	cout<<s<<'\n';
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int T=1;
    while(T--) solve();
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 8112
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(void){
	int n,m,c,i,j,sum=0;
	priority_queue<int,vector<int>,greater<int>> que;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>m;
		for(j=0;j<m;j++){
			cin>>c;
			que.push(c);
		}
		for(j=0;j<m-1;j++) que.pop();
	}
	for(i=0;i<n;i++){
		sum+=que.top();
		que.pop();
	}
	cout<<sum<<endl;
	return 0;
}
accuracy: 0.8666666666666667
time_ms: 80
memory_kb: 5004
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;

using i64 = long long;

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define repi(i, a, b) for (int i = (a) - 1; i >= (b); --i)

int main() {
    int n;
    cin >> n;
    vector<vector<int>> s(n);
    rep (i, 0, n) {
        int m;
        cin >> m;
        s[i].resize(m);
        rep (j, 0, m) {
            cin >> s[i][j];
        }
    }
    i64 sum = 0;
    multiset<int> st;
    repi (i, n, 0) {
        rep (j, 0, s[i].size()) st.insert(s[i][j]);
        sum += *rbegin(st);
        st.erase(prev(end(st)));
    }
    cout << sum << endl;
    return 0;
}
accuracy: 1
time_ms: 120
memory_kb: 19364
final_rank: 14

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main(){
	#define int long long
	int n;
	cin >>n;
	vector<vector<int>>s(n);
	for(int i = 0;i < n;i++){
		int m;
		cin >>m;
		s[i].resize(m);
		for(int j = 0;j < m;j++){
			cin >>s[i][j];
		}
	}
	multiset<int>p;
	int ans = 0;
	for(int i = n-1;i >= 0;i--){
		for(int j = 0;j < s[i].size();j++){
			p.insert(s[i][j]);
		}
		// cout <<"[";
		// for(auto i:p){
		// 	cout <<i<<" ";
		// }
		// cout <<"]\n";
		auto itr = p.end();
		itr--;
		ans += *itr;
		p.erase(itr);
	}
	cout <<ans<<"\n";
}
accuracy: 1
time_ms: 130
memory_kb: 19708
final_rank: 15

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >>n;
	vector<vector<int>>s(n);
	for(int i = 0;i < n;i++){
		int m;
		cin >>m;
		s[i].resize(m);
		for(int j = 0;j < m;j++){
			cin >>s[i][j];
		}
	}
	multiset<int>p;
	int ans = 0;
	for(int i = n-1;i >= 0;i--){
		for(int j = 0;j < s[i].size();j++){
			p.insert(s[i][j]);
		}
		// cout <<"[";
		// for(auto i:p){
		// 	cout <<i<<" ";
		// }
		// cout <<"]\n";
		auto itr = p.end();
		itr--;
		ans += *itr;
		p.erase(itr);
	}
	cout <<ans<<"\n";
}
accuracy: 0.8666666666666667
time_ms: 120
memory_kb: 19376
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

#ifdef LOCAL
#include <debug_print.hpp>
#define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (static_cast<void>(0))
#endif

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N;
    cin >> N;
    vector<int> L(N);
    vector<vector<int>> A(N);
    // 客の価値と i の pair
    vector<pair<int, int>> B;
    for (int i = 0; i < N; i++) {
        cin >> L[i];
        A[i].resize(L[i]);
        for (int j = 0; j < L[i]; j++) {
            cin >> A[i][j];
            B.emplace_back(A[i][j], i);
        }
    }

    ll ans = 0;
    // 後ろのタクシーから客を決めていく
    priority_queue<int> que;
    for (int i = N - 1; i >= 0; i--) {
        // i 番目にタクシー乗り場に乗っている人を que に追加
        for (int j = 0; j < L[i]; j++) que.emplace(A[i][j]);
        // タクシー i は que から最大の客を乗せる
        int max_value = que.top();
        que.pop();
        ans += max_value;
    }

    cout << ans << '\n';
}
accuracy: 1
time_ms: 40
memory_kb: 23760
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;

#ifdef LOCAL
#include <debug_print.hpp>
#define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (static_cast<void>(0))
#endif

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N;
    cin >> N;
    vector<int> L(N);
    vector<vector<int>> A(N);
    // 客の価値と i の pair
    vector<pair<int, int>> B;
    for (int i = 0; i < N; i++) {
        cin >> L[i];
        A[i].resize(L[i]);
        for (int j = 0; j < L[i]; j++) {
            cin >> A[i][j];
            B.emplace_back(A[i][j], i);
        }
    }

    int ans = 0;
    // 後ろのタクシーから客を決めていく
    priority_queue<int> que;
    for (int i = N - 1; i >= 0; i--) {
        // i 番目にタクシー乗り場に乗っている人を que に追加
        for (int j = 0; j < L[i]; j++) que.emplace(A[i][j]);
        // タクシー i は que から最大の客を乗せる
        int max_value = que.top();
        que.pop();
        ans += max_value;
    }

    cout << ans << '\n';
}
accuracy: 0.8666666666666667
time_ms: 40
memory_kb: 24516
final_rank: 19

code_snippet: #include<bits/stdc++.h>
using namespace std;

#define int long long

/*
17:29~17:43
6:25~
*/

signed main(){
	int n;cin>>n;
	priority_queue<int> pq;
	for(int i=1;i<=n;i++){
		int m;cin>>m;
		while(m--){
			int x;cin>>x;
			pq.push(-x);
		}
		while(pq.size()>i)pq.pop();
	}
	int ans=0;
	while(pq.size()){
		ans-=pq.top();pq.pop();
	}
	cout<<ans<<endl;
}
accuracy: 1
time_ms: 80
memory_kb: 8436
final_rank: 4

code_snippet: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    vector<vector<int>> a(n);
    rep(i,n){
        int m;
        cin >> m;
        a[i].resize(m);
        rep(j,m) cin >> a[i][j];
    }

    reverse(a.begin(),a.end());

    priority_queue<int> pq;
    ll ans = 0;
    rep(i,n){
        for(int e:a[i]) pq.push(e);

        ans += pq.top();
        pq.pop();
    }
    cout << ans << endl;
}
accuracy: 1
time_ms: 40
memory_kb: 19408
final_rank: 8

code_snippet: #include<bits/stdc++.h>
using namespace std;
vector<int> v[300000];
int m[300000];
int main(void)
{
	int n,i,j,c;
	long long sum;
	priority_queue<int> qu;
	cin >>n;
	for(i=0;i<n;i++)	{
		cin >>m[i];
		for(j=0;j<m[i];j++)	{
			cin >>c;
			v[i].push_back(c);
		}
	}
	sum=0;
	for(i=n-1;i>=0;i--)	{
		for(j=0;j<m[i];j++)	{
			qu.push(v[i][j]);
		}
		sum+=qu.top();
		qu.pop();
	}
	cout <<sum<<endl;
	return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 20616
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  priority_queue<long long> que;
  for(int i = 0; i < N; i++) {
    int M, s;
    cin >> M;
    for(int j = 0; j < M; j++) {
      cin >> s;
      que.push(-s);
    }
    while(int(que.size()) > i+1) que.pop();
  }
  long long ans = 0;
  while(!que.empty()) {
    ans += -que.top();
    que.pop();
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 80
memory_kb: 7888
final_rank: 3