Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <set>
  4. #include <algorithm>
  5. #include <cmath>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. int main() {
  11. if (::getenv("LOCAL_PC")) {
  12. freopen("input.txt", "r", stdin);
  13. freopen("output.txt", "w", stdout);
  14. ios_base::sync_with_stdio(false);
  15. cin.tie(0);
  16. cout.tie(0);
  17. }
  18.  
  19. int w, n, m;
  20. cin >> w >> n >> m;
  21. vector<int> a(n);
  22. vector<int> b(m);
  23.  
  24. int amax = -1;
  25. for (int i = 0; i < n; i++) {
  26. cin >> a[i];
  27. amax = max(amax, a[i]);
  28. }
  29.  
  30. int bmax = -1;
  31. for (int j = 0; j < m; j++) {
  32. cin >> b[j];
  33. bmax = max(bmax, b[j]);
  34. }
  35.  
  36. int ans = (int)1e9;
  37. for (int i = amax; i <= (w - bmax); i++) {
  38. int linesA = 1;
  39. int sum = -1;
  40. for (auto e : a) {
  41. sum += e + 1;
  42. if (sum > i) {
  43. sum = e;
  44. linesA++;
  45. }
  46. }
  47.  
  48. int linesB = 1;
  49. sum = -1;
  50. for (auto e : b) {
  51. sum += e + 1;
  52. if (sum > (w - i)) {
  53. sum = e;
  54. linesB++;
  55. }
  56. }
  57. ans = min(ans, max(linesA, linesB));
  58. }
  59. cout << ans << endl;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement