/* HDU 6000 - Wash [ 贪心 ] 题意: L 件衣服,N 个洗衣机,M 个烘干机,给出每个洗衣机洗一件衣服的时间和烘干机烘干一件衣服的时间,问需要的最少时间是多少 分析: 先求出L件衣服最优洗衣时间的数组,再求出最优烘干时间的数组 然后排序按最小值+最大值的思路贪心,取最大值 可以看成排序后两数组咬合 */ #include <bits/stdc++.h> using namespace std; #define LL long long const int N = 1e5+5; const int MAXL = 1e6+5; struct Node { LL x; int y; friend operator < (Node a, Node b) { if (a.x == b.x) return a.y > b.y; return a.x > b.x; } }; priority_queue<Node> Q; int t, l, n, m; int w[N], d[N]; LL a[MAXL], b[MAXL]; void solve(int w[], int n, LL a[]) { while (!Q.empty()) Q.pop(); for (int i = 1; i <= n; i++) Q.push(Node{w[i], w[i]}); for (int i = 1; i <= l; i++) { Node tmp = Q.top(); Q.pop(); a[i] = tmp.x; tmp.x += tmp.y; Q.push(tmp); } } int main() { scanf("%d", &t); for (int tt = 1; tt <= t; tt++) { scanf("%d%d%d", &l, &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &w[i]); for (int i = 1; i <= m; i++) scanf("%d", &d[i]); solve(w, n, a); solve(d, m, b); LL ans = 0; for (int i = 1; i <= l; i++) { ans = max(ans, a[i] + b[l-i+1]); } printf("Case #%d: %lld ", tt, ans); } }