Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- struct sigment {
- long long left = 0, right = 0;
- };
- int main() {
- long long n, m,t,k;
- cin >> n >> m >> t >> k;
- vector < sigment > a(n), b(m);
- long long start = 0;
- for (int i = 0; i < n; i++) {
- long long end;
- cin >> end;
- a[i] = { start, end };
- start = end + k;
- }
- a.push_back({ start, t });
- start = 0;
- for (int i = 0; i < m; i++) {
- long long end;
- cin >> end;
- b[i] = { start, end };
- start = end + k;
- }
- b.push_back({ start, t });
- long long timeA, timeB, time;
- timeA = timeB = time = 0;
- long long ia = 0;
- long long ib = 0;
- long long ch = 1;
- while (true) {
- if (time >= t)
- break;
- if (ch == 1) {
- while (true) {
- if (a[ia].left >= t) {
- cout << timeA << " " << timeB << endl;
- system("pause");
- return 0;
- }
- if (a[ia].right > time) {
- break;
- }
- ia++;
- }
- long long start = max(time, a[ia].left);
- timeA += a[ia].right - start;
- time = a[ia].right;
- ia++;
- ch = 2;
- continue;
- }
- if (ch == 2) {
- while (true) {
- if (b[ib].left >= t) {
- cout << timeA << " " << timeB << endl;
- system("pause");
- return 0;
- }
- if (b[ib].right > time) {
- break;
- }
- ib++;
- }
- long long start = max(time, b[ib].left);
- timeB += b[ib].right - start;
- time = b[ib].right;
- ib++;
- ch = 1;
- continue;
- }
- }
- cout << timeA << " " << timeB << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement