Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. struct sigment {
  8. long long left = 0, right = 0;
  9. };
  10.  
  11. int main() {
  12. long long n, m,t,k;
  13. cin >> n >> m >> t >> k;
  14. vector < sigment > a(n), b(m);
  15.  
  16. long long start = 0;
  17. for (int i = 0; i < n; i++) {
  18. long long end;
  19. cin >> end;
  20. a[i] = { start, end };
  21. start = end + k;
  22. }
  23. a.push_back({ start, t });
  24.  
  25. start = 0;
  26.  
  27. for (int i = 0; i < m; i++) {
  28. long long end;
  29. cin >> end;
  30. b[i] = { start, end };
  31. start = end + k;
  32. }
  33. b.push_back({ start, t });
  34.  
  35. long long timeA, timeB, time;
  36. timeA = timeB = time = 0;
  37.  
  38. long long ia = 0;
  39. long long ib = 0;
  40.  
  41. long long ch = 1;
  42.  
  43. while (true) {
  44. if (time >= t)
  45. break;
  46. if (ch == 1) {
  47.  
  48. while (true) {
  49. if (a[ia].left >= t) {
  50. cout << timeA << " " << timeB << endl;
  51. system("pause");
  52. return 0;
  53. }
  54. if (a[ia].right > time) {
  55. break;
  56. }
  57. ia++;
  58. }
  59. long long start = max(time, a[ia].left);
  60. timeA += a[ia].right - start;
  61. time = a[ia].right;
  62. ia++;
  63. ch = 2;
  64. continue;
  65. }
  66.  
  67.  
  68. if (ch == 2) {
  69. while (true) {
  70. if (b[ib].left >= t) {
  71. cout << timeA << " " << timeB << endl;
  72. system("pause");
  73. return 0;
  74. }
  75. if (b[ib].right > time) {
  76. break;
  77. }
  78. ib++;
  79. }
  80. long long start = max(time, b[ib].left);
  81. timeB += b[ib].right - start;
  82. time = b[ib].right;
  83. ib++;
  84. ch = 1;
  85. continue;
  86. }
  87. }
  88.  
  89. cout << timeA << " " << timeB << endl;
  90. system("pause");
  91. return 0;
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement