#include<bits/stdc++.h> #define int long long usingnamespace std; pair<int, int> p[105]; int dp[105][10005]; signedmain() { int n, i, j, k, sum = 0, res = 0; scanf("%lld", &n); for (i = 1; i <= n; i++) { scanf("%lld", &p[i].second); sum += p[i].second; } for (i = 1; i <= n; i++) scanf("%lld", &p[i].first); sort(p + 1, p + 1 + n); for (i = n; i; i--) { res += p[i].first; if (res >= sum) break; } res = n - i + 1; memset(dp, -12, sizeof(dp)); dp[0][0] = 0; for (i = 1; i <= n; i++) { for (j = i; j; j--) { for (k = 10000; k >= 0; k--) { if (k >= p[i].first) dp[j][k] = max({dp[j][k], dp[j][k + 1], dp[j - 1][k - p[i].first] + p[i].second}); else dp[j][k] = max(dp[j][k], dp[j][k + 1]); } } } printf("%lld %lld", res, sum - dp[res][sum]); return0; }