Pagini recente » Cod sursa (job #120895) | Cod sursa (job #40560) | Cod sursa (job #2973891) | Cod sursa (job #2039929) | Cod sursa (job #1805899)
#include <fstream>
#include <set>
using namespace std;
ifstream fin("fabrica.in");
ofstream fout("fabrica.out");
const int nmax= 100000;
const int nrmax= 50000;
int a[nrmax+1], b[nrmax+1], x[nmax+1], y[nmax+1];
struct str {
int x, y;
};
struct str_cmp {
bool operator () ( const str &x, const str &y ) {
return x.x<y.x;
}
};
inline str mp( int x, int y ) {
str sol;
sol.x= x, sol.y= y;
return sol;
}
multiset <str, str_cmp> s1, s2;
int main( ) {
int n, nra, nrb;
fin>>n>>nra>>nrb;
for ( int i= 1; i<=nra; ++i ) {
fin>>a[i];
s1.insert( mp( a[i], a[i] ) );
}
for ( int i= 1; i<=nrb; ++i ) {
fin>>b[i];
s2.insert( mp( b[i], b[i] ) );
}
for ( int i= 1; i<=n; ++i ) {
str aux1= *s1.begin(), aux2= *s2.begin();
s1.erase( s1.begin() ), s2.erase( s2.begin() );
x[i]= aux1.x, y[n-i+1]= aux2.x;
aux1.x+= aux1.y, aux2.x+= aux2.y;
s1.insert( aux1 ), s2.insert( aux2 );
}
int sol1= x[n], sol2= 0;
for ( int i= 1; i<=n; ++i ) {
sol2= max(sol2, x[i]+y[i]);
}
fout<<sol1<<" "<<sol2<<"\n";
return 0;
}