Accepted solution

1150A - Stock Arbitraging

Open original problem
Source code

#include <iostream>

#include<vector>

#include<string>

#include<math.h>

#include<set>

#include<map>

#include<stack>

#include<queue>

#include<algorithm>

/* ==================================================

  |                                                  |

  |    Author: *** S. M. Sabiul Hajjaj Sabit ***     |

  |       Last Edit:  May,14,2019                    |

   ================================================== */

///***global declaration***///

#define all(arr) arr.begin(),arr.end()

#define pb push_back

#define sz(x) x.size()

#define min3(a,b,c)  min(min(a,b),c)

#define max3(a,b,c)  max(max(a,b),c)

using namespace std;

int i,j,n,m,sum=0,ans=0;

template <typename T>long long int power(T a, T b)

{

    long long int pow=1;

    for(int i=0; i<b; i++)

    {

        pow *= a;

    }

    return pow;

}

///*********Write Code From Here*********///

int main()

{

    int n,m,r;

    int mor=0,ev=0;

    vector<int>arrn,arrm;

    cin>>n>>m>>r;

    for(int i=0; i<n; i++)

    {

        int t;

        cin>>t;

        arrn.pb(t);

    }

    for(int i=0; i<m; i++)

    {

        int t;

        cin>>t;

        arrm.pb(t);

    }

    sort(all(arrn));

    sort(all(arrm));

    int temp=r;

    for(i=0; i<sz(arrn); i++)

    {

        if(temp>=arrn[i])

        {

            mor += temp/arrn[i];

            temp %= arrn[i];

            //  cout<<temp<<endl;

        }

    }

    // temp=mor;

    ev = mor*arrm[m-1];

    if(ev+temp>r)

    {

        cout<<ev+temp<<endl;

    }

    else

    {

        cout<<r<<endl;

    }

    //cout<<mor<<endl;

}
Join the discussion

Add your comment