Pagini recente » Cod sursa (job #270968) | Cod sursa (job #697430) | Cod sursa (job #1531710) | Cod sursa (job #2926846) | Cod sursa (job #585918)
Cod sursa(job #585918)
#include <cstdio>
#include <queue>
#include <algorithm>
#define MAXN 100005
using namespace std;
int A[MAXN], B[MAXN], N, nrA, nrB;
struct Point {
int x, y;
bool operator < (const Point &o) const {
return x + A[y] > o.x + A[o.y];
}
};
struct Point2 {
int x, y;
bool operator < (const Point2 &o) const {
return x + B[y] > o.x + B[y];
}
};
priority_queue <Point> Q1;
priority_queue <Point2> Q2;
Point nod; Point2 nod2;
int mx, i, T[MAXN], add;
int main ()
{
freopen ("fabrica.in", "r", stdin);
freopen ("fabrica.out", "w", stdout);
scanf ("%d %d %d\n", &N, &nrA, &nrB);
for (i = 1; i <= nrA; i++) {
scanf ("%d\n", &A[i]);
nod.x = 0; nod.y = i;
Q1.push (nod);
}
for (i = 1; i <= nrB; i++) {
scanf ("%d\n", &B[i]);
nod2.x = 0; nod2.y = i;
Q2.push (nod2);
}
for (i = 1; i <= N; i++) {
nod = Q1.top ();
Q1.pop ();
nod.x += A[nod.y];
mx = nod.x;
T[i] = nod.x;
Q1.push (nod);
}
sort (T + 1, T + N + 1);
for (i = 1; i <= N; i++) {
nod2 = Q2.top ();
Q2.pop ();
if (T[i] > B[nod2.y]) add = T[i] - B[nod2.y];
nod2.x += B[nod2.y] + add;
Q2.push (nod2);
// printf ("%d %d %d\n", time[i], nod2.x, nod2.y);
}
printf ("%d %d\n", nod.x, nod2.x);
return 0;
}