This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 500 + 7;
const int K = 10;
const int MX = 100 + 7;
int score[N][K];
int f[K][MX];
int n, k, c;
vector<int> team, v;
void rec(int cnt = 1) {
if (cnt == k + 1) {
vector<int> total(k + 1, 0);
for (auto &i : team) {
for (int j = 1; j <= k; j++) {
total[j] = max(total[j], score[i][j]);
}
}
int now = 0;
for (int j = 1; j <= k; j++) {
now += total[j];
}
v.push_back(now);
return;
}
int start = (team.empty() ? 1 : team.back() + 1);
for (int i = start; i <= n; i++) {
team.push_back(i);
rec(cnt + 1);
team.pop_back();
}
}
signed main() {
#ifdef ONPC
freopen ("input.txt", "r", stdin);
#else
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif // ONPC
cin >> n >> k >> c;
int mx = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k; j++) {
cin >> score[i][j];
mx = max(mx, score[i][j]);
f[j][score[i][j]]++;
}
}
if (mx <= 10) {
vector<int> config_final;
function<void(int)> solve = [&](int lvl) {
if (lvl == k + 1) {
ll ways = 1;
for (int i = 1; i <= k; i++) {
ways *= f[i][config_final[i - 1]];
}
c -= ways;
if (c <= 0) {
int sol = 0;
for (auto &i : config_final) {
sol += i;
}
cout << sol << "\n";
exit(0);
}
return;
}
for (int i = mx; i >= 1; i--) {
config_final.push_back(i);
solve(lvl + 1);
config_final.pop_back();
}
};
solve(1);
return 0;
}
rec();
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
cout << v[c - 1] << "\n";
return 0;
}
/**
dp[i][mxa][mxb] = ?
**/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |