Submission #256521

#TimeUsernameProblemLanguageResultExecution timeMemory
256521BlagojceOlympiads (BOI19_olympiads)C++11
0 / 100
89 ms53624 KiB
#include <bits/stdc++.h> 
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
#include <time.h>
#include <cmath>
 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
 
const int i_inf = 1e9;
const ll inf = 1e17;
const ll mod = 1000000007;
const ld eps = 1e-13;
const ld pi  = 3.14159265359;
 
mt19937 _rand(time(NULL));
clock_t timer = clock();
const int mxn = 502;

int n, k, c;
int a[mxn][6];

bool vis[5000][mxn];
vector<int> v[1000000];

int ans(int p){
	int cnt = 0;
	fr(i, 0, n){
		if(vis[p][i]) continue;
		++cnt;
	}
	if(cnt < k) return -i_inf;
	
	int res = 0;
	fr(j, 0, k){	
		int best = -1, mx = -1; 
		fr(i, 0, n){
			if(vis[p][i] || find(all(v[p]), i) != v[p].end()) continue;
			if(a[i][j] > mx){
				mx = a[i][j];
				best = i;
			}
		}
		v[p].pb(best);
	}
	fr(i, 0, k){
		int mx = 0;
		for(auto u : v[p]) mx = max(mx, a[u][i]);
		res += mx;
	}
	return res;
	
}

int search(){
	int pos = 0;
	int ret = 0;
	int processed = 0;
	
	pq<pair<int, int> > Q;
	
	Q.push({ans(0), 0});
	
	while(processed < c){
		int curr = Q.top().nd;
		ret = Q.top().st;
		Q.pop();
		++processed;
		for(auto u : v[curr]){
			memcpy(vis[++pos], vis[curr], sizeof(vis[curr]));
			vis[pos][u] = true;
			Q.push({ans(pos), pos});
		}
		
	}
	 
	return ret;
	
	
}

void solve(){
	cin >> n >> k >> c;
	fr(i, 0, n){
		fr(j, 0, k){
			cin >> a[i][j];
		}
	}
	cout<<search()<<endl;
}
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...