Guest User

Untitled

a guest
Dec 2nd, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. 4 10
  2. 5 10 15 20
  3. 100 50 100 300
  4.  
  5. 400
  6.  
  7. 5 15
  8. 2 14 25 31 37
  9. 8 19 20 11 25
  10.  
  11. 44
  12.  
  13. #include <algorithm>
  14. #include <iostream>
  15. #include <vector>
  16.  
  17. std::vector<int> f(const std::vector<int> &first, const std::vector<int> &v1, const std::vector<int> &v2, int n1, int n2) {
  18. int a = -1000000000;
  19. std::vector<int> ans(n1);
  20. for (int i = 0; i != n1; ++i) {
  21. if (v1[i] <= n2) {
  22. ans[i] = a;
  23. } else {
  24. std::vector<int> A(n1);
  25. int j = 0;
  26. while (abs(v1[i] - v1[j]) > n2) {
  27. A[j] = first[j];
  28. ++j;
  29. }
  30. int m = *std::max_element(A.begin(), A.end());
  31. if (m == 0) {
  32. ans[i] = a;
  33. } else {
  34. ans[i] = m + v2[i];
  35. }
  36. }
  37. }
  38. return ans;
  39. }
  40.  
  41. int main() {
  42. int n1, n2;
  43. std::cin >> n1 >> n2;
  44. std::vector<int> v1(n1);
  45. for (size_t i = 0; i != n1; ++i) {
  46. std::cin >> v1[i];
  47. }
  48. std::vector<int> v2(n1);
  49. for (size_t i = 0; i != n1; ++i) {
  50. std::cin >> v2[i];
  51. }
  52. std::vector<int> ans;
  53. std::vector<int> c = f(v2, v1, v2, n1, n2);
  54. ans.push_back(*std::max_element(c.begin(), c.end()));
  55. for (int i = 0; i != n1; ++i) {
  56. std::vector<int> x = f(c, v1, v2, n1, n2);
  57. ans.push_back(*std::max_element(x.begin(), x.end()))
  58. c = x;
  59. }
  60. std::cout << *std::max_element(ans.begin(), ans.end());
  61. return 0;
  62. }
Add Comment
Please, Sign In to add comment