H2.cpp 883 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = 1e5 + 5;
  4. int f[maxn];
  5. int main()
  6. {
  7. int s, x1, x2;
  8. int t1, t2;
  9. int p, d;
  10. cin >> s >> x1 >> x2 >> t1 >> t2 >> p >> d;
  11. int ans = abs(x2 - x1) * t2;
  12. int to = x2 - x1;
  13. if(to < 0) to = -1;
  14. else to = 1;
  15. if(to == 1)
  16. {
  17. if(d == 1)
  18. {
  19. if(p <= x1) ans = min((x2 - p) * t1, ans);
  20. else ans = min((s - p + s + x2) * t1, ans);
  21. }
  22. else
  23. {
  24. ans = min(ans, (p + x2) * t1);
  25. }
  26. }
  27. else
  28. {
  29. if(d == -1)
  30. {
  31. if(p >= x1) ans = min((p - x2) * t1, ans);
  32. else ans = min((p + s + s - x2) * t1,ans);
  33. }
  34. else
  35. {
  36. ans = min(ans, (s - p + s - x2) * t1);
  37. }
  38. }
  39. cout << ans << endl;
  40. return 0;
  41. }