Cod sursa(job #587762)

Utilizator GavrilaVladGavrila Vlad GavrilaVlad Data 5 mai 2011 20:00:40
Problema Fabrica Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <stdio.h>
#include <algorithm>
#include <set>

using namespace std;

#define maxn 100010

int n, i, j, k, nra, nrb, sb, sa;
int a[maxn], b[maxn], ta[maxn], tb[maxn];
multiset<pair<int, int> > g;

void solve(int v[], int t[], int lim)
{
    for(int i=1; i<=lim; ++i)
    {
        scanf("%d", &v[i]);
        g.insert(make_pair(v[i], v[i]));
    }

    for(int i=1; i<=n; ++i)
    {
        t[i]=g.begin()->first;
        g.insert(make_pair(t[i]+(g.begin()->second), g.begin()->second));
        g.erase(g.begin());
    }

    g.clear();
}


int main()
{
    freopen("fabrica.in", "r", stdin);
    freopen("fabrica.out", "w", stdout);

    scanf("%d%d%d", &n, &nra, &nrb);

    solve(a, ta, nra);
    solve(b, tb, nrb);

    sa=ta[n];
    sb=0;
    for(int i=1; i<=n; ++i)
        sb=max(sb, ta[i]+tb[n-i+1]);

    printf("%d %d\n", sa, sb);
    return 0;
}