#include <bits/stdc++.h>
using namespace std;
#define int long long
int scores[507][6];
int n, k, c;
vector<pair<int, int>> res;
map<pair<pair<int, int>, vector<int>>, int> store;
void recur(int x, int remain, vector<int> cur, int cnt){
if (x == n){
if (remain == 0){
int lol = 0;
for (int y = 0; y < k; y++) lol += cur[y];
res.push_back({lol, cnt});
}
return;
}
store[{{x+1, remain}, cur}] += cnt;
if (remain != 0){
for (int y = 0; y < k; y++){
cur[y] = max(cur[y], scores[x][y]);
}
store[{{x+1, remain-1}, cur}] += cnt;
}
}
main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> k >> c;
for (int x = 0; x < n; x++){
for (int y = 0; y < k; y++){
cin >> scores[x][y];
}
}
vector<int> init;
for (int x = 0; x < k; x++){
init.push_back(LLONG_MIN/20);
}
store[{{0, k}, init}] = 1;
while (!store.empty()){
auto vals = *store.begin();
recur(vals.first.first.first, vals.first.first.second, vals.first.second, vals.second);
store.erase(store.begin());
}
sort(res.begin(), res.end(), greater<pair<int, int>>());
c -= 2;
int sum = 0;
for (int x = res.size()-1; x > -1; x--){
sum += res[x].second;
if (sum >= c){
cout << res[x].first;
break;
}
}
}
Compilation message
olympiads.cpp:38:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
38 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2043 ms |
7480 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1280 ms |
65852 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2032 ms |
33020 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2043 ms |
7480 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |