Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int s, x1, x2, t1, t2, p;
- int dir;
- int solve()
- {
- scanf("%d %d %d %d %d %d %d", &s, &x1, &x2, &t1, &t2, &p, &dir);
- int ans = abs(x1 - x2) * t2;
- int rx1 = 0;
- int rx2 = abs(x1 - x2) * t1;
- int ndir = 1;
- if (x1 > x2)
- ndir = -1;
- if (ndir == 1)
- {
- if (dir == 1)
- {
- if (p > x1)
- {
- rx1 = (s - p) * t1 + s * t1 + x2 * t1;
- ans = min(rx1, ans);
- }
- else
- {
- rx1 = (x2 - p) * t1;
- ans = min(rx1, ans);
- }
- }
- else
- {
- rx1 = p * t1 + x2 * t1;
- ans = min(rx1, ans);
- }
- }
- else
- {
- if (dir == 1)
- {
- rx1 = (s - p) * t1 + (s - x2) * t1;
- ans = min(rx1, ans);
- }
- else
- {
- if (p > x1)
- {
- rx1 = (p - x2) * t1;
- ans = min(rx1, ans);
- }
- else
- {
- rx1 = p * t1 + s * t1 + (s - x2) * t1;
- ans = min(rx1, ans);
- }
- }
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement