/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 488.0 KiB
#3 Accepted 1ms 560.0 KiB
#4 Accepted 3ms 420.0 KiB
#5 Accepted 32ms 568.0 KiB
#6 Accepted 216ms 1.309 MiB
#7 Accepted 196ms 1.25 MiB
#8 Accepted 196ms 1.398 MiB
#9 Accepted 200ms 1.379 MiB
#10 Accepted 2ms 364.0 KiB

Code

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long int ll;


using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mod 1000000007

ll lcm(ll a,ll b)
{
    return (a*b)/__gcd(a,b);
}


ll binExp(ll a,ll b)
{
    if(b==0)
        return 1;

    ll res=binExp(a,b/2);

    if(b&1)
    {
        return (a*res*res)%mod;

    }
    else
    {
        return (res*res)%mod;
    }
}


bool isPrime(ll n)
{
    for(ll i=2; i*i<=n; i++)
    {
        if(n%i==0)
        {
            return false;
        }
    }

    return true;
}




void solve()
{
   ll n,d;
   cin>>n>>d;

   ll a,b;
   cin>>a>>b;

   if(n<=d)
   {
       cout<<n*a<<endl;
   }
   else
   {
       ll ans=0;
       ans+=(d*a);
       n-=d;
       ans+=(n*b);

       cout<<ans<<endl;
   }


}















int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);





    ll t;

    cin>>t;
  //  t=1;






    ll caseNo=1;



    while(t--)
    {
        //  cout<<"Case "<<caseNo<<": ";
        // caseNo++;

        solve();


    }




    return 0;

}

Information

Submit By
Type
Submission
Problem
P1090 Summer trip
Contest
Brain Booster #5
Language
C++20 (G++ 13.2.0)
Submit At
2024-09-05 15:37:58
Judged At
2024-09-05 15:37:58
Judged By
Score
100
Total Time
216ms
Peak Memory
1.398 MiB