USACO Job Processing

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
ID: wcr19961
PROG: job
LANG: C++11
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;

const int maxn = 1010;
int a[maxn], b[maxn];

struct node {
int x, dt;
node(int x, int dt) : x(x), dt(dt) {}
bool operator < (const node& rhs) const {
return x > rhs.x;
}
};

void proc(int* p, int n, int m) {
priority_queue<node> q;
while (m--) {
int x;
scanf("%d", &x);
q.push(node(x, x));
}
for (int i = 0; i < n; ++i) {
node k = q.top();
q.pop();
p[i] = k.x;
k.x += k.dt;
q.push(k);
}
}

int main() {
freopen("job.in", "r", stdin);
freopen("job.out", "w", stdout);
int n, m1, m2;
scanf("%d%d%d", &n, &m1, &m2);
proc(a, n, m1);
sort(a, a + n);
proc(b, n, m2);
sort(b, b + n);
int ans = 0;
for (int i = 0; i < n; ++i) {
ans = max(ans, a[i] + b[n - i - 1]);
}
printf("%d %d\n", a[n - 1], ans);
return 0;
}