Cod sursa(job #586901)

Utilizator deneoAdrian Craciun deneo Data 3 mai 2011 11:49:13
Problema Fabrica Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 kb
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;

struct cmp
{
	bool operator()(const pair<int, int> &a, const pair<int, int> &b)const 
	{
		return (a.first + a.second) > (b.first + b.second);
	}
};

priority_queue< pair<int, int>, vector< pair<int, int> >, cmp > pa, pb;
int nrdoze, nra, nrb;

int main() {
	int i, ax, tdozai, _maxtdozai = -1, _max = - 1; 
	
	freopen("fabrica.in", "rt", stdin);
	freopen("fabrica.out", "wt", stdout);
	scanf("%d%d%d", &nrdoze, &nra, &nrb);
	for(i = 1; i <= nra; ++i) {
		scanf("%d", &ax);
		pa.push( make_pair(0, ax)  );
	}
	for(i = 1; i <= nrb; ++i) {
		scanf("%d", &ax);
		pb.push( make_pair(0, ax)  );
	}
	
	for(i = 1; i <= nrdoze; ++i) {
		tdozai = pa.top() . first + pa.top() . second;
		ax = pa.top() . second;
		pa.pop();
		pa.push( make_pair(tdozai, ax) );
		
		if( tdozai > _max )
			_max = tdozai;
			
		tdozai = max(tdozai, pb.top() . first);
		ax = pb.top() . second;
		tdozai += ax;
		pb.pop();
		pb.push( make_pair(tdozai, ax) );
		
		if( tdozai > _maxtdozai)
			_maxtdozai = tdozai;
	}
	printf("%d %d\n", _max, _maxtdozai);
	return 0;
}