Cod sursa(job #586840)

Utilizator freak93Adrian Budau freak93 Data 3 mai 2011 01:21:10
Problema Fabrica Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.22 kb
#include <fstream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

const char iname[] = "fabrica.in";
const char oname[] = "fabrica.out";

ifstream f(iname);
ofstream g(oname);

void solve(const int &N, const vector<int> &processors, vector<int> &times) {
	set< pair<int, int> > S;
	vector<int> current_time(processors.size(), 0);
	for (vector<int>::const_iterator it = processors.begin(); it != processors.end(); ++it) {
		current_time[it - processors.begin()] = *it;
		S.insert(make_pair(*it, it - processors.begin()));
	}
	for (int i = 0; i < N; ++i) {
		times[i] = S.begin() -> first;
		int processor = S.begin() -> second;

		S.erase(S.begin());
		current_time[processor] += processors[processor];
		S.insert(make_pair(current_time[processor], processor));
	}  
}

int main() {
	int N, NrA, NrB; f >> N >> NrA >> NrB;

	vector<int> A(NrA);
	for (int i = 0; i < NrA; ++i)
		f >> A[i];
	
	vector<int> B(NrB);
	for (int i = 0; i < NrB; ++i)
		f >> B[i];
	
	vector<int> timesA(N), timesB(N);
	solve(N, A, timesA); solve(N, B, timesB);
	
	reverse(timesB.begin(), timesB.end());

	int answer = 0;
	for (int i = 0; i < N; ++i) 
		answer = max(answer, timesA[i] + timesB[i]);
	
	g << timesA.back() << " " << answer << "\n";
}