#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define Inf INT32_MAX
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
int n, k, c, sMin;
vector<pair<int, vi>> C;
multiset<int> S;
void f(int t, int j, int s, vi m) {
int x, sNew, sNewMax;
vi mNew;
if (t == 0) {
S.insert(s);
if (S.size() > c) {
S.erase(S.begin());
sMin = *S.begin();
}
}
else {
for (int i = j; i < n; i++) {
sNewMax = 0;
sNew = 0;
mNew = vi(k);
for (int l = 0; l < k; l++) {
x = max(m[l], C[i].second[l]);
sNew += x;
mNew[l] = x;
sNewMax += max(x, C[i].first);
}
if (sNewMax < sMin) return;
f(t - 1, i + 1, sNew, mNew);
}
}
}
int main() {
ios_base::sync_with_stdio(false);
int s, sMax;
cin >> n >> k >> c;
C = vector<pair<int, vi>>(n, {0, vi(k)});
for (int i = 0; i < n; i++) {
sMax = 0;
for (int j = 0; j < k; j++) {
cin >> s;
C[i].second[j] = s;
sMax = max(sMax, s);
}
C[i].first = sMax;
}
sort(C.begin(), C.end(), greater<pair<int, vi>>());
sMin = 0;
f(k, 0, 0, vi(k));
cout << sMin << endl;
return 0;
}
Compilation message
olympiads.cpp: In function 'void f(int, int, int, vi)':
olympiads.cpp:24:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (S.size() > c) {
~~~~~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
504 KB |
Output is correct |
2 |
Correct |
4 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
500 KB |
Output is correct |
4 |
Correct |
27 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
504 KB |
Output is correct |
2 |
Correct |
50 ms |
424 KB |
Output is correct |
3 |
Correct |
4 ms |
504 KB |
Output is correct |
4 |
Correct |
7 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2032 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
504 KB |
Output is correct |
2 |
Correct |
4 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
500 KB |
Output is correct |
4 |
Correct |
27 ms |
376 KB |
Output is correct |
5 |
Correct |
9 ms |
504 KB |
Output is correct |
6 |
Correct |
50 ms |
424 KB |
Output is correct |
7 |
Correct |
4 ms |
504 KB |
Output is correct |
8 |
Correct |
7 ms |
504 KB |
Output is correct |
9 |
Execution timed out |
2032 ms |
376 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |