Cod sursa(job #2402309)

Utilizator robx12lnLinca Robert robx12ln Data 10 aprilie 2019 16:31:40
Problema Fabrica Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.16 kb
#include<bits/stdc++.h>
using namespace std;

ifstream fin("fabrica.in");
ofstream fout("fabrica.out");

const int DIM = 5e4 + 5;

int A, B, arr_A[DIM], arr_B[DIM], N;
int Ans1[2 * DIM], Ans2[2 * DIM], Ans;

priority_queue< pair<int,int>,
                vector< pair<int,int> >,
                greater< pair<int,int> > > prq_A, prq_B;

int main(){

    fin >> N >> A >> B;
    for( int i = 1; i <= A; i++ ){
        fin >> arr_A[i];
        prq_A.push( { arr_A[i], i } );
    }

    for( int i = 1; i <= B; i++ ){
        fin >> arr_B[i];
        prq_B.push( { arr_B[i], i } );
    }

    for( int i = 1; i <= N; i++ ){
        Ans1[i] = prq_A.top().first;
        int x = prq_A.top().second;
        prq_A.pop();
        prq_A.push( {Ans1[i] + arr_A[x], x} );
    }

    for( int i = N; i >= 1; i-- ){
        Ans2[i] = prq_B.top().first;
        int x = prq_B.top().second;
        prq_B.pop();
        prq_B.push( {Ans2[i] + arr_B[x], x} );
    }
    int ans = 0;
    for( int i = 1; i <= N; i++ ){
        ans = max( ans, Ans1[i] );
        Ans = max( Ans, Ans1[i] + Ans2[i] );
    }
    fout << ans << " " << Ans;
    return 0;
}