贪心加二分 虽然比赛后才过 ........
/*************************************************************************
> Author: xlc2845 > Mail: xlc2845@gmail.com
> Created Time: 2013年11月10日 星期日 19时35分23秒
************************************************************************/ #include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cstdlib>
#define N 100010
#define ll long long using namespace std; int n, m;
ll a, b[N], p[N]; ll ok(int t)
{
if(t == 0) return 0;
if(t > m)
return -1;
int j = n-1;
ll cost = 0, cs = 0;
for(int i = t-1; i >= 0; i--, j--)
{
if(b[j] < p[i])
cost += p[i]-b[j];
cs += min(b[j], p[i]);
}
if(cost > a) return -1;
cs -= (a-cost);
if(cs < 0) cs = 0;
return cs;
} int main()
{
scanf("%d%d%I64d", &n, &m, &a);
for(int i = 0; i < n; i++)
scanf("%I64d", &b[i]);
for(int i = 0; i < m; i++)
scanf("%I64d",&p[i]);
sort(b, b+n);
sort(p, p+m);
int l = 0, r = n;
int ans = -1;
ll cost, tmp;
while(l <= r)
{
int mid = (l+r)/2;
if((tmp = ok(mid)) >= 0)
{
cost = tmp;
ans = mid;
l = mid+1;
}
else
r = mid-1;
}
printf("%d %I64d", ans, cost);
return 0;
}