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;
const int maxn = 510;
int mat[maxn][10];
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int n, k, c;
cin >> n >> k >> c;
for(int i=1; i<=n; i++){
for(int j=1; j<=k; j++){
cin >> mat[i][j];
}
}
vector<int> pos;
if(k == 1){
for(int a=1; a<=n; a++) pos.push_back(mat[a][1]);
}
else if(k == 2){
for(int a=1; a<=n; a++){
for(int b=a+1; b<=n; b++){
int ans = 0;
for(int i=1; i<=k; i++) ans += max(mat[a][i], mat[b][i]);
pos.push_back(ans);
}
}
}
else if(k == 3){
for(int a=1; a<=n; a++){
for(int b=a+1; b<=n; b++){
for(int c=b+1; c<=n; c++){
int ans = 0;
for(int i=1; i<=k; i++) ans += max({mat[a][i], mat[b][i], mat[c][i]});
pos.push_back(ans);
}
}
}
}
else if(k == 4){
for(int a=1; a<=n; a++){
for(int b=a+1; b<=n; b++){
for(int c=b+1; c<=n; c++){
for(int d=c+1; d<=n; d++){
int ans = 0;
for(int i=1; i<=k; i++) ans += max({mat[a][i], mat[b][i], mat[c][i], mat[d][i]});
pos.push_back(ans);
}
}
}
}
}
else if(k == 5){
for(int a=1; a<=n; a++){
for(int b=a+1; b<=n; b++){
for(int c=b+1; c<=n; c++){
for(int d=c+1; d<=n; d++){
for(int e=d+1; e<=n; e++){
int ans = 0;
for(int i=1; i<=k; i++) ans += max({mat[a][i], mat[b][i], mat[c][i], mat[d][i], mat[e][i]});
pos.push_back(ans);
}
}
}
}
}
}
else{
for(int a=1; a<=n; a++){
for(int b=a+1; b<=n; b++){
for(int c=b+1; c<=n; c++){
for(int d=c+1; d<=n; d++){
for(int e=d+1; e<=n; e++){
for(int f=e+1; f<=n; f++){
int ans = 0;
for(int i=1; i<=k; i++) ans += max({mat[a][i], mat[b][i], mat[c][i], mat[d][i], mat[e][i], mat[f][i]});
pos.push_back(ans);
}
}
}
}
}
}
}
sort(pos.begin(), pos.end());
reverse(pos.begin(), pos.end());
cout << pos[c-1] << endl;
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... |