1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define all(a) a.begin(),a.end()
#define v vector
#define pb push_back

priority_queue<v<LL>>stosy;

int main(){ios_base::sync_with_stdio(0);cin.tie(0);
    LL n, k, a, s=0;
    cin >> n >> k >> a;
    for(int i=0;i<n;i++){
        v<LL>lista(k);
        for(int j=0;j<k;j++){
            cin >> lista[k-j-1];
        }
        stosy.push(lista);
    }
    while(a--){
        v<LL>tym;
        tym=stosy.top();
        stosy.pop();
        s+=tym[0];
        v<LL>lista(tym.size()-1);
        for(int i=1;i<tym.size();i++) lista[i-1]=tym[i];
        stosy.push(lista);
    }
    cout << s;
    
    return 0;
}