Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <cmath>
- #include <iterator>
- using namespace std;
- using ll=long long int;
- int main()
- {
- ll n, m, t, k;
- cin >> n >> m >> t >> k;
- vector <ll> a(n + 1), b(m + 1);
- for (auto i = a.begin() + 1; i != a.end(); i++)
- cin >> (*i);
- for (auto i = b.begin() + 1; i != b.end(); i++)
- cin >> (*i);
- bool ona = true;
- ll curt = 0, at = 0, bt = 0, ai = 0, bi = 0;
- a[ai] = curt;
- b[bi] = curt;
- while (curt < t)
- {
- if (ona)
- {
- while (a[ai] >= a[ai + 1])
- {
- swap(a[ai], a[ai + 1]);
- ai++;
- }
- while (b[bi] >= b[bi + 1])
- {
- swap(b[bi], b[bi + 1]);
- bi++;
- }
- if(ai != 0 and a[ai] - k < a[ai - 1]){ curt = a[ai - 1] + k; a[ai] = curt; b[bi] = curt;}
- if (curt >= t) break;
- if (ai == n)
- {
- at += t - curt;
- curt = t; a[ai] = curt;
- }
- else
- {
- at += a[ai + 1] - curt;
- curt = a[ai + 1]; a[ai] = curt; b[bi] = curt;
- ona = !(ona);
- }
- }
- else{
- while (b[bi] >= b[bi + 1])
- {
- swap(b[bi], b[bi + 1]);
- bi++;
- }while (a[ai] >= a[ai + 1])
- {
- swap(a[ai], a[ai + 1]);
- ai++;
- }
- if(bi != 0 and b[bi] - k < b[bi - 1]){ curt = b[bi - 1] + k;a[ai] = curt; b[bi] = curt;}
- if (curt >= t) break;
- if (bi == m)
- {
- bt += t - curt;
- curt = t;a[ai] = curt; b[bi] = curt;
- }
- else
- {
- bt += b[bi + 1] - curt;
- curt = b[bi + 1];a[ai] = curt; b[bi] = curt;
- ona = !(ona);
- }
- }
- }
- cout << at << " " << bt;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement