C - Road To Zero
Note
In the first test case you can perform the following sequence of operations: first, second, first. This way you spend 391+555+391=1337391+555+391=1337 dollars.
In the second test case both integers are equal to zero initially, so you dont’ have to spend money.
题意
给出两个整数x,y按步骤同时为零,一种花费a元x或y一者加减一,第二种花费b元同时加减一
思路
x,y之间差一定需要第一种消除消除之后比较2*a和b的大小决定方法。
代码
#include>
#include
using namespace std;
int main(){
int t;
cin>>t;
while(t–){
long long a,b,x,y,minab,minxy;
cin>>x>>y;
cin>>a>>b;
minab=b;
if(2a<b)minab=2a;
minxy=x;
if(x>y)minxy=y;
cout<<abs(x-y)a+minabminxy<<endl;
}
}