➤ Problem Link : 1342A. Road To Zero
✅ C++ Solution :
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
int main() {
int t;
cin>>t;
while(t--)
{
ll x,y,a,b;
cin>>x>>y;
cin>>a>>b;
ll ans=LONG_MAX;
ll diff=abs(y-x);
ans=(x+y)*a;
if(x<y)
ans=min(ans,x*b+diff*a);
else
ans=min(ans,y*b +diff*a);
cout<<ans<<"\n";
}
}
Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook.
😇Happy Learning!!
