A. Road To Zero(水 Educational Codeforces Round 86 Rated for Div. 2)

A. Road To Zero (Wednesday)

CF 1342A

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;
    }
}

Guess you like

Origin blog.csdn.net/weixin_44986601/article/details/105829221