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")
#define fi first
#define se second
#define ll long long
#define pb push_back
#define ii pair<int,int>
const int nax=5e2+5;
int tab[2005][6];
int n,k,c;
void compare(vector<int> &v){
for (int i = 0; i < k; ++i)
{
for (int j = i+1; j < (int)v.size(); ++j)
{
if(tab[v[j]][i]>tab[v[i]][i]) swap(v[i],v[j]);
}
}
return;
}
int val(vector<int> &v){
int sum=0;
for (int i = 0; i < k; ++i)
{
int mx=0;
for (int j = 0; j < k; ++j)
{
mx=max(mx,tab[v[j]][i]);
}
sum+=mx;
}
return sum;
}
int main()
{
cin>>n>>k>>c;
vector<int> cur;
for (int i = 0; i < n; ++i)
{
cur.pb(i);
for (int j = 0; j < k; ++j)
{
cin>>tab[i][j];
}
}
compare(cur);
priority_queue<tuple<int,int,vector<int>>> pq;
pq.push({val(cur),0,cur});
while(c--){
auto [ans,pos,v] = pq.top();
//cout <<ans<<" "<<pos<<" "<<v.size()<<endl;
pq.pop();
if(c==0){
cout << ans<<endl;
return 0;
}
if(v.size()==k) continue;
for (int i = pos; i < k; ++i)
{
vector<int> nxt=v;
nxt.erase(nxt.begin()+i);
compare(nxt);
pq.push({val(nxt),i,nxt});
}
}
}
Compilation message (stderr)
olympiads.cpp: In function 'int main()':
olympiads.cpp:59:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
59 | if(v.size()==k) continue;
| ~~~~~~~~^~~
# | 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... |