# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
863779 | Trisanu_Das | Olympiads (BOI19_olympiads) | C++17 | 0 ms | 0 KiB |
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;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
int n, m, k, sMin, sMax;
vector<pair<int, vector<int> > > C;
multiset<int> S;
bool f(int t, int j, int s, vector<int> x){
int xx, sNew, sNewMax;
vector<int> xNew;
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 = vector<int>(k);
for (int l = 0; l < k; l++) {
x = max(x[l], C[i].second[l]);
sNew += xx;
xNew[l] = xx;
sNewMax += max(xx, C[i].first);
}
if (sNewMax < sMin) return false;
if (f(t - 1, i + 1, sNew, xNew)) return true;
}
}
return false;
}
int main() {
ios_base::sync_with_stdio(false);
int x, xMax;
vector<int> M;
cin >> n >> k >> c;
C = vector<pair<int, vector<int> > >(n, {0, vector<int>(k)});
M = vector<int>(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 << '\n';
}