fork download
  1. // ~~ icebear ~~
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #define int long long
  5. typedef long long ll;
  6. typedef pair<int, int> ii;
  7. typedef pair<int, ii> iii;
  8.  
  9. template<class T>
  10. bool minimize(T &a, const T &b) {
  11. if (a > b) return a = b, true;
  12. return false;
  13. }
  14.  
  15. template<class T>
  16. bool maximize(T &a, const T &b) {
  17. if (a < b) return a = b, true;
  18. return false;
  19. }
  20.  
  21. #define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
  22. #define FORR(i,a,b) for(int i=(a); i>=(b); --i)
  23. #define REP(i, n) for(int i=0; i<(n); ++i)
  24. #define RED(i, n) for(int i=(n)-1; i>=0; --i)
  25. #define MASK(i) (1LL << (i))
  26. #define BIT(S, i) (((S) >> (i)) & 1)
  27. #define mp make_pair
  28. #define pb push_back
  29. #define fi first
  30. #define se second
  31. #define all(x) x.begin(), x.end()
  32. #define task "trortr"
  33. /*END OF TEMPLATE. ICEBEAR AND THE CAT WILL WIN VOI26 */
  34.  
  35. const int MOD = 1e9 + 7;
  36. const int inf = 1e9 + 27092008;
  37. const ll INF = 1e18 + 27092008;
  38. const int N = 2e5 + 5;
  39. int n, x, y, z, a[N], b[N];
  40. namespace Subtask1 {
  41. bool check() {
  42. return x + y <= z;
  43. }
  44.  
  45. void solve() {
  46. int ans = 0;
  47. FOR(i, 1, n) if (a[i] > b[i])
  48. ans += (a[i] - b[i]) * y;
  49. else ans += (b[i] - a[i]) * x;
  50. cout << ans << '\n';
  51. }
  52. }
  53.  
  54.  
  55. namespace Subtask2 {
  56. bool check() {
  57. return x == y && y == z;
  58. }
  59.  
  60. void solve() {
  61. int ans = 0;
  62. FOR(i, 1, n - 1) {
  63. if (a[i] < b[i] && a[i + 1] > b[i + 1]) {
  64. int have = min(a[i + 1] - b[i + 1], b[i] - a[i]);
  65. ans += have * z;
  66. a[i + 1] -= have;
  67. a[i] += have;
  68. } else if (a[i] > b[i] && a[i + 1] < b[i + 1]) {
  69. int have = min(a[i] - b[i], b[i + 1] - a[i + 1]);
  70. ans += have * z;
  71. a[i + 1] += have;
  72. a[i] -= have;
  73. }
  74.  
  75. if (a[i] > b[i]) ans += (a[i] - b[i]) * y;
  76. else ans += (b[i] - a[i]) * x;
  77. }
  78. if (a[n] > b[n]) ans += (a[n] - b[n]) * y;
  79. else ans += (b[n] - a[n]) * x;
  80. cout << ans << '\n';
  81. }
  82. }
  83.  
  84. namespace Subtask4 {
  85. bool check() {
  86. return max(*max_element(a + 1, a + n + 1), *max_element(b + 1, b + n + 1)) <= 3000;
  87. }
  88.  
  89. void solve() {
  90. priority_queue<int> Q[2];
  91. vector<int> cost({y, x});
  92. int ans = 0;
  93. FOR(i, 1, n) {
  94. bool T = (a[i] < b[i]);
  95.  
  96. REP(tries, abs(a[i] - b[i])) {
  97. if (Q[T].empty() || (i * z - Q[T].top() > cost[T])) {
  98. ans += cost[T];
  99. Q[T^1].push(i * z + cost[T]);
  100. } else {
  101. ans += i * z - Q[T].top();
  102. Q[T^1].push(i * 2 * z - Q[T].top());
  103. Q[T].pop();
  104. }
  105. }
  106. }
  107. cout << ans << '\n';
  108. }
  109. }
  110.  
  111. void init(void) {
  112. cin >> n >> x >> y >> z;
  113. FOR(i, 1, n) cin >> a[i];
  114. FOR(i, 1, n) cin >> b[i];
  115. }
  116.  
  117. void process(void) {
  118. if (Subtask1 :: check()) Subtask1 :: solve();
  119. else if (Subtask2 :: check()) Subtask2 :: solve();
  120. else if (Subtask4 :: check()) Subtask4 :: solve();
  121. }
  122.  
  123. signed main() {
  124. ios_base::sync_with_stdio(0);
  125. cin.tie(0); cout.tie(0);
  126. if (fopen(task".inp", "r")) {
  127. freopen(task".inp", "r", stdin);
  128. freopen(task".out", "w", stdout);
  129. }
  130. int tc = 1;
  131. cin >> tc;
  132. while(tc--) {
  133. init();
  134. process();
  135. }
  136. return 0;
  137. }
  138.  
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
0