A. Road To Zero (Wednesday)
Meaning of the title: Given x, y.
- Operation 1: Spend a, add/subtract 1 to one of x and y
- Operation 2: Spend b, add/subtract 1 to x and y simultaneously
Ask the minimum cost
Idea: Three cases, take the minimum
int n;
int main(){
int t,tt,f1=0;
LL x,a,b,y,ans;
t=ird();
while(t--){
x=lrd();y=lrd();a=lrd();b=lrd();
ans=(x+y)*a;
ans=min(ans,min(x,y)*b+a*(max(x,y)-min(x,y)));
ans=min(ans,max(x,y)*a+b*(max(x,y-min(x,y))));
cout<<ans<<endl;
}
}