Precreation contest files
This commit is contained in:
43
Codeforces/CodeforcesRound1035(Div2)/AAddorXOR/solution.cpp
Normal file
43
Codeforces/CodeforcesRound1035(Div2)/AAddorXOR/solution.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#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();
|
||||
}
|
||||
Reference in New Issue
Block a user