44 lines
701 B
C++
44 lines
701 B
C++
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
void solve() {
|
|
int a, b, x, y;
|
|
cin >> a >> b >> x >> y;
|
|
|
|
if (a > b) {
|
|
if (a - b == 1) {
|
|
if (a % 2 != 0) {
|
|
cout << y << endl;
|
|
return;
|
|
}
|
|
}
|
|
cout << "-1\n";
|
|
|
|
return;
|
|
}
|
|
|
|
int diff = b - a;
|
|
int xdiff = diff * x;
|
|
if (diff % 2 == 0) {
|
|
cout << min(xdiff, ((diff * x) / 2) + ((diff * y) / 2)) << endl;
|
|
return;
|
|
} else {
|
|
if (a % 2 != 0) {
|
|
|
|
cout << min(xdiff, (diff / 2 + 1) * x + (diff / 2) * y) << endl;
|
|
return;
|
|
} else {
|
|
cout << min(xdiff, (diff / 2) * x + (diff / 2 + 1) * y) << endl;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
int main() {
|
|
int t;
|
|
cin >> t;
|
|
while (t--)
|
|
solve();
|
|
}
|