Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long int ll;
- int main() {
- ios::sync_with_stdio(false);
- cin.tie(NULL);
- ll qa, qb, sa, sb, w, n, m;
- cin >> qa >> qb >> sa >> sb >> w >> n >> m;
- ll bob_time = qb * sb + sb + w;
- ll alice_time = qa * sa + sa + w;
- vector<ll> aliceq(n), bobq(m);
- for (int i = 0; i < n; ++i) {
- cin >> aliceq[i];
- }
- for (int i = 0; i < m; ++i) {
- cin >> bobq[i];
- }
- ll ansBob = -1;
- ll last = qb * sb;
- for (int i = 0; i < m; ++i) {
- ll x = bobq[i];
- if (x > alice_time) {
- if (alice_time < last) {
- ansBob = last + sb;
- } else {
- ansBob = alice_time + sb;
- }
- break;
- }
- if (x < last) {
- last += sb;
- } else {
- last = x + sb;
- }
- }
- if (ansBob == -1) {
- if (alice_time < last) {
- ansBob = last + sb;
- } else {
- ansBob = alice_time + sb;
- }
- }
- ll ansAlice = -1;
- last = qa * sa;
- for (int i = 0; i < n; ++i) {
- ll x = aliceq[i];
- if (x > bob_time) {
- if (bob_time < last) {
- ansAlice = last + sa;
- } else {
- ansAlice = bob_time + sa;
- }
- break;
- }
- if (x < last) {
- last += sa;
- } else {
- last = x + sa;
- }
- }
- if (ansAlice == -1) {
- if (bob_time < last) {
- ansAlice = last + sa;
- } else {
- ansAlice = bob_time + sa;
- }
- }
- // cout << alice_time << ' ' << ansAlice << '\n';
- // cout << bob_time << ' ' << ansBob << '\n';
- cout << min(ansAlice, ansBob) << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment