Hacker Rank Candy Piles

/*
Lionel Messi is such a player that you may catch him, you may touch him, you may feel him
and definitely you may Love him.
Lionel Messi is Messi. A little Magician in this World.

*/

#include<bits/stdc++.h>

using namespace std;

#define fast ios_base::sync_with_stdio(0)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
#define psb push_back

typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;

const int mod = 1000007;
const int high = 100003;

// modified needed.................................
LL bigmod(LL a , LL b , LL c)
{
    if(!b) return 1;

    if(!(b & 1))
    {
        LL x = bigmod(a , b / 2 , c)%c;
        return ((x % c) * (x % c ))%c;
    }

    else
        return ((a%c) * (bigmod(a , b-1, c) %c ))%c;
}
//......................................................

LL modInverse(LL a, LL mod){return bigmod(a , mod-2 , mod);}

class sample
{
public:
    void ek(int x)
    {
        cout << x << "\n";
    }

    void dui(int x , int y)
    {
        cout << x << " " << y << "\n";
    }

    void tin(int x , int y , int z)
    {
        cout <<  x << " " << y << " " << z << "\n";
    }
};

LL ar[high] , br[high];

int main()
{
    fast;
    sample samobj;
    int n , i , way , in;

    while(cin >> n)
    {
        LL mini = 1000005;
        memset(ar , 0 , sizeof ar);

        for(i=1; i<=n; i++)
        {
            cin >> br[i];
            ar[br[i]]++;
            if(mini > br[i])
            {
                mini = br[i];
                in = i;
            }
        }

        if(ar[mini] > 1) way = n;
        else way = 1;

        br[in] = mini * 2;

        mini = 1000005;

        for(i=1; i<=n; i++)
        {
            mini = min(mini , br[i]);
        }

        cout << mini << " " << way << "\n";
    }

    return 0;
}

Comments

Popular posts from this blog

SPOJ-CMG - Collecting Mango

LightOJ 1009 - Back to Underworld

LeetCode Palindrome Number