Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int long long
- using namespace std;
- signed main() {
- ios::sync_with_stdio(false);
- cin.tie(0);
- #ifdef LOCAL
- freopen("input", "r", stdin);
- #endif
- int n, m, t, k;
- cin >> n >> m >> t >> k;
- vector<int> a(n + 1);
- a[0] = -k;
- vector<int> b(m + 1);
- b[0] = -k;
- for (int i = 1; i <= n; i++)
- cin >> a[i];
- for (int i = 1; i <= m; i++)
- cin >> b[i];
- a.push_back(t);
- b.push_back(t);
- sort(a.begin(), a.end());
- sort(b.begin(), b.end());
- int tt = 0;
- int cntA = 0, cntB = 0;
- int ch = 0;
- while (tt < t) {
- if (ch == 0) {
- auto adL = --upper_bound(a.begin(), a.end(), tt);
- tt = max(tt, *adL + k);
- if (tt >= t)
- break;
- auto adR = *upper_bound(a.begin(), a.end(), tt);
- cntA += adR - tt;
- tt = adR;
- } else {
- auto adL = --upper_bound(b.begin(), b.end(), tt);
- tt = max(tt, *adL + k);
- if (tt >= t)
- break;
- auto adR = *upper_bound(b.begin(), b.end(), tt);
- cntB += adR - tt;
- tt = adR;
- }
- ch ^= 1;
- }
- cout << cntA << ' ' << cntB << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement