Pagini recente » Cod sursa (job #1246292) | Cod sursa (job #2374924) | Cod sursa (job #2894176) | Cod sursa (job #990106) | Cod sursa (job #586658)
Cod sursa(job #586658)
#include <fstream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef unsigned int uint;
int N, Na, Nb;
int T1[100002], T2[100002], Times[100002];
int canBeg[100002];
int Ta, Tb;
class compare
{
public: bool operator () (const int& i1, const int& i2)
{
return canBeg[i1] < canBeg[i2];
}
};
int Heap[100002];
void Push(int val)
{
Heap[++Heap[0]] = val;
int C = Heap[0], F = Heap[0] >> 1;
while (F)
{
if (canBeg[Heap[C]] > canBeg[Heap[F]])
swap(Heap[C], Heap[F]);
else break;
C >>= 1, F >>= 1;
}
}
void Pop()
{
Heap[1] = Heap[Heap[0]--];
int C = 2, F = 1;
while (C <= Heap[0])
{
C += (C < Heap[0] && canBeg[Heap[C]] < canBeg[Heap[C + 1]]);
if (canBeg[Heap[F]] < canBeg[Heap[C]])
swap(Heap[F], Heap[C]);
else break;
F = C, C >>= 1;
}
}
bool ok1(int time)
{
int total = 0;
for (int i = 1; i <= Na; ++i)
total += time / T1[i];
return (total >= N);
}
bool ok2(int time)
{
Heap[0] = 0;
for (int i = 1; i <= Nb; ++i)
{
canBeg[i] = time - T2[i];
Push(i);
}
for (int i = N; i >= 1; --i)
if (Times[i] <= canBeg[Heap[1]])
{
int aux = Heap[1]; Pop();
canBeg[aux] -= T2[aux];
Push(aux);
}
else return false;
return true;
}
int main()
{
ifstream fin("fabrica.in");
ofstream fout("fabrica.out");
fin >> N >> Na >> Nb;
for (int i = 1; i <= Na; ++i)
fin >> T1[i];
for (int i = 1; i <= Nb; ++i)
fin >> T2[i];
int step = 1 << 30;
for (Ta = step + 1; step; step >>= 1)
if (Ta - step >= 1 && ok1(Ta - step))
Ta -= step;
for (int i = 1; i <= Na; ++i)
for (int j = 1; j <= Ta / T1[i]; ++j)
Times[++Times[0]] = T1[i] * j;
sort(Times + 1, Times + Times[0] + 1);
Times[0] = N;
step = 1 << 30;
for (Tb = step + 1; step; step >>= 1)
if (Tb - step >= 1 && ok2(Tb - step))
Tb -= step;
fout << Ta << ' ' << Tb;
fin.close();
fout.close();
}