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;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define long unsigned long
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define lb lower_bound
#define ub upper_bound
#define sz(v) int((v).size())
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define PI 2*acos(0.0)
int n, k;
ll grid[500][6], c;
multiset <int> scores;
vector <int> inds;
void calc(int i, int cnt) {
if (cnt == k) {
ll val = 0;
for (int j = 0; j < k; j++) {
ll mx = 0;
for (int l = 0; l < k; l++) {
mx = max(mx, grid[inds[l]][j]);
}
val += mx;
}
scores.insert(val);
if (sz(scores) > c) {
scores.erase(scores.begin());
}
return;
}
if (i == n) return;
inds.pb(i);
for (int j = i+1; j <= n; j++) {
calc(j, cnt+1);
if (cnt+1 == k) break;
}
inds.pop_back();
}
void solve() {
cin >> n >> k >> c;
for (int i = 0; i < n; i++) {
for (int j = 0; j < k; j++) {
cin >> grid[i][j];
}
}
for (int i = 0; i < n; i++) {
calc(i, 0);
}
cout << (*scores.begin());
}
int main() {
do_not_disturb
int t = 1;
//~ cin >> t;
while (t--) {
solve();
}
return 0;
}
/*
*/
# | 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... |