Cod sursa(job #587761)

Utilizator GavrilaVladGavrila Vlad GavrilaVlad Data 5 mai 2011 19:57:36
Problema Fabrica Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 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[])
{
    for(int i=1; i<=nra; ++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);
    solve(b, tb);

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

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