Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <set>
- #include <algorithm>
- #include <cmath>
- using namespace std;
- int main() {
- if (::getenv("LOCAL_PC")) {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- }
- int w, n, m;
- cin >> w >> n >> m;
- vector<int> a(n);
- vector<int> b(m);
- int amax = -1;
- for (int i = 0; i < n; i++) {
- cin >> a[i];
- amax = max(amax, a[i]);
- }
- int bmax = -1;
- for (int j = 0; j < m; j++) {
- cin >> b[j];
- bmax = max(bmax, b[j]);
- }
- int ans = (int)1e9;
- for (int i = amax; i <= (w - bmax); i++) {
- int linesA = 1;
- int sum = -1;
- for (auto e : a) {
- sum += e + 1;
- if (sum > i) {
- sum = e;
- linesA++;
- }
- }
- int linesB = 1;
- sum = -1;
- for (auto e : b) {
- sum += e + 1;
- if (sum > (w - i)) {
- sum = e;
- linesB++;
- }
- }
- ans = min(ans, max(linesA, linesB));
- }
- cout << ans << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement