Accepted solution

1206A - Choose Two Numbers

Open original problem
Source code

#include <iostream>

#include<vector>

#include<string>

#include<string.h>

#include<math.h>

#include<set>

#include<map>

#include<list>

#include<stack>

#include<queue>

#include <fstream>

#include<iterator>

#include<algorithm>

#include <iomanip>      // std::setprecision

#include<unordered_set>

#include<sstream>

#include<cstdio>

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

  |                                                  |

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

  |       Last Edit:  July,25,2019                    |

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

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

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

#define pb push_back

#define mp make_pair

#define lb lower_bound

#define up upper_bound

#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)

#define lli long long int

#define prnt(x) cout<<x<<endl

#define in1(x) cin>>x

#define in12(x,y) cin>>x>>y

using namespace std;

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;

}

template <typename T> string tostr(const T& t)

{

    ostringstream os;

    os<<t;

    return os.str();

}

bool isPrime(int n)

{

    int ans=true;

    for(int i=2; i<=n/2; i++)

    {

        if(n%i == 0)

        {

            ans = false;

            break;

        }

    }

    if (ans)

        return true;

    else

        return false;

}

/**** ascending sort vector of pair basis fd 2nd element******/

//sort(arr.begin(), arr.end(),sortbysec);

bool sortbysec(const pair<int,int> &a,const pair<int,int> &b)

{

    //return (a.second < b.second); //ascending

    return (a.second > b.second);  //descending

}

///File Handel

//freopen("input.txt", "r", stdin)

//freopen("output.txt", "w", stdout)

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

int main()

{

    int a[205]= {0};

    int b[205]= {0};

    int n,m;

    cin>>n;

    vector<int>a1,b1;

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

    {

        int t;

        cin>>t;

        a1.pb(t);

        a[t]=1;

    }

    cin>>m;

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

    {

        int t;

        cin>>t;

        b1.pb(t);

        b[t]=1;

    }

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

    {

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

        {

            int t = a1[i]+b1[j];

            if(t<=200)

            {

                if(a[t]!=1 && b[t]!=1)

                {

                    cout<<a1[i]<<" "<<b1[j]<<endl;

                    return 0;

                }

            }

            else

            {

                cout<<a1[i]<<" "<<b1[j]<<endl;

                return 0;

            }

        }

    }

}
Join the discussion

Add your comment