-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChaîne de production.cpp
46 lines (41 loc) · 1.09 KB
/
Chaîne de production.cpp
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
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
vector<int> solve(vector<int>& machines, vector<int>& jobs) {
sort(all(jobs));
int m = machines.size(), j = jobs.size();
vector<int> cum(m, 0), ans(j, INT_MAX);
for (int job = 0; job < j; job++) {
pii mini = make_pair(INT_MAX, -1);
for (int i = 0; i < m; i++)
mini = min(mini, make_pair(cum[i] + machines[i], i));
ans[job] = mini.first;
cum[mini.second] = mini.first;
}
sort(all(ans));
for (int job = 0; job < j; job++) ans[job] += jobs[j - job - 1];
return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int A;
cin >> A;
vector<int> a(A);
for (auto& i : a) cin >> i;
int B;
cin >> B;
vector<int> b(B);
for (auto& i : b) cin >> i;
vector<int> input(n, 0);
auto output1 = solve(a, input);
auto ans1 = *max_element(all(output1));
cout << ans1 << "\n";
auto output2 = solve(b, output1);
auto ans2 = *max_element(all(output2));
cout << ans2 << "\n";
}