Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <cmath>
  5. #include <iterator>
  6.  
  7. using namespace std;
  8. using ll=long long int;
  9.  
  10. int main()
  11. {
  12. ll n, m, t, k;
  13. cin >> n >> m >> t >> k;
  14. vector <ll> a(n + 1), b(m + 1);
  15. for (auto i = a.begin() + 1; i != a.end(); i++)
  16. cin >> (*i);
  17. for (auto i = b.begin() + 1; i != b.end(); i++)
  18. cin >> (*i);
  19. bool ona = true;
  20. ll curt = 0, at = 0, bt = 0, ai = 0, bi = 0;
  21. a[ai] = curt;
  22. b[bi] = curt;
  23. while (curt < t)
  24. {
  25. if (ona)
  26. {
  27. while (a[ai] >= a[ai + 1])
  28. {
  29. swap(a[ai], a[ai + 1]);
  30. ai++;
  31. }
  32. while (b[bi] >= b[bi + 1])
  33. {
  34. swap(b[bi], b[bi + 1]);
  35. bi++;
  36. }
  37. if(ai != 0 and a[ai] - k < a[ai - 1]){ curt = a[ai - 1] + k; a[ai] = curt; b[bi] = curt;}
  38. if (curt >= t) break;
  39. if (ai == n)
  40. {
  41. at += t - curt;
  42. curt = t; a[ai] = curt;
  43. }
  44. else
  45. {
  46. at += a[ai + 1] - curt;
  47. curt = a[ai + 1]; a[ai] = curt; b[bi] = curt;
  48. ona = !(ona);
  49. }
  50. }
  51. else{
  52. while (b[bi] >= b[bi + 1])
  53. {
  54. swap(b[bi], b[bi + 1]);
  55. bi++;
  56. }while (a[ai] >= a[ai + 1])
  57. {
  58. swap(a[ai], a[ai + 1]);
  59. ai++;
  60. }
  61. if(bi != 0 and b[bi] - k < b[bi - 1]){ curt = b[bi - 1] + k;a[ai] = curt; b[bi] = curt;}
  62. if (curt >= t) break;
  63. if (bi == m)
  64. {
  65. bt += t - curt;
  66. curt = t;a[ai] = curt; b[bi] = curt;
  67. }
  68. else
  69. {
  70. bt += b[bi + 1] - curt;
  71. curt = b[bi + 1];a[ai] = curt; b[bi] = curt;
  72. ona = !(ona);
  73. }
  74. }
  75. }
  76. cout << at << " " << bt;
  77. return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement