#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, sMax;
vector<pair<int, vi>> C;
multiset<int> S;
bool 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();
if (sMin == sMax) return true;
}
}
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 false;
if (f(t - 1, i + 1, sNew, mNew)) return true;
}
}
return false;
}
int main() {
ios_base::sync_with_stdio(false);
int x, xMax;
vi M;
cin >> n >> k >> c;
C = vector<pair<int, vi>>(n, {0, vi(k)});
M = vi(k);
for (int i = 0; i < n; i++) {
xMax = 0;
for (int j = 0; j < k; j++) {
cin >> x;
C[i].second[j] = x;
xMax = max(xMax, x);
M[j] = max(M[j], x);
}
C[i].first = xMax;
}
sort(C.begin(), C.end(), greater<pair<int, vi>>());
sMin = 0;
sMax = 0;
for (int i = 0; i < k; i++) {
sMax += M[i];
}
f(k, 0, 0, vi(k));
cout << sMin << endl;
return 0;
}
Compilation message
olympiads.cpp: In function 'bool f(int, int, int, vi)':
olympiads.cpp:24:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (S.size() > c) {
~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
504 KB |
Output is correct |
2 |
Correct |
4 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
508 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
504 KB |
Output is correct |
2 |
Correct |
50 ms |
480 KB |
Output is correct |
3 |
Correct |
4 ms |
376 KB |
Output is correct |
4 |
Correct |
7 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
504 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
56 ms |
520 KB |
Output is correct |
4 |
Correct |
14 ms |
508 KB |
Output is correct |
5 |
Correct |
6 ms |
504 KB |
Output is correct |
6 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
504 KB |
Output is correct |
2 |
Correct |
4 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
508 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
8 ms |
504 KB |
Output is correct |
6 |
Correct |
50 ms |
480 KB |
Output is correct |
7 |
Correct |
4 ms |
376 KB |
Output is correct |
8 |
Correct |
7 ms |
504 KB |
Output is correct |
9 |
Correct |
55 ms |
504 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
56 ms |
520 KB |
Output is correct |
12 |
Correct |
14 ms |
508 KB |
Output is correct |
13 |
Correct |
6 ms |
504 KB |
Output is correct |
14 |
Correct |
4 ms |
376 KB |
Output is correct |
15 |
Execution timed out |
2035 ms |
504 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |