In this HackerEarth War problem solution, Alice and Bob are playing the legendary game of Age of Empires. They are trying extremely hard to be strategic, and smart - but are failing to do so. They’re newbies at the game and are just learning the parts of the game.

They don’t have an idea about the strength and weaknesses of various units in the game. So, they start creating random units based on how good cool they look to them. But, that’s a terrible strategy on the battlefield of the Age of Empires.

To play a fair game, both Alice and Bob generate the same number of units, N. We’re given two arrays representing the strength of the units of both of their armies. The first array represents Bob’s army, the second one represents Alice’s army.

Now, the fight begins. But, how does one come to know who wins? Simple way actually. Every soldier in either army starts going on a rampage and starts killing every soldier of the opposite army, which has less strength. The army which destroys the other army wins the war and wins the game between two newbies. If such a case is not possible, the result will thus be a TIE!

Help yourself to find the result of the game!


HackerEarth War problem solution


HackerEarth War problem solution.

#include <bits/stdc++.h>
using namespace std;
int main()
{
  int test;
  cin>>test;
  while(test--){
  int N;
  cin>>N;
  int a[N],b[N];
  for(int i=0;i<N;i++)
    cin>>a[i];
  for(int i=0;i<N;i++)
    cin>>b[i];
  sort(a,a+N);
  sort(b,b+N);
  if(a[N-1]>b[N-1])
    cout<<"Bob"<<endl;
  else if(a[N-1]<b[N-1])
    cout<<"Alice"<<endl;
  else
    cout<<"Tie"<<endl;
  }
  return 0;
}


Second solution

#include<bits/stdc++.h>

using namespace std;

#define vi vector < int >
#define pii pair < int , int >
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define foreach(it,v) for( __typeof((v).begin())it = (v).begin() ; it != (v).end() ; it++ )
#define ll long long
#define llu unsigned long long
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define all(x) x.begin(),x.end()
#define mset(x,v) memset(x, v, sizeof(x))
#define sz(x) (int)x.size()

int a[100006];
int b[100006];

int main()
{
    int t;
    cin >> t;
    assert(1 <= t && t <= 5);
    while(t--)
    {
        int n , i;
        cin >> n;
        assert(1 <= n && n <= 100000);
        int mxa = 0 , mxb = 0;
        for(i=0;i<n;i++)
        {
            cin >> a[i];
            assert(0 <= a[i] && a[i] <= (int)1e9);
            mxa = max(mxa,a[i]);
        }
        for(i=0;i<n;i++)
        {
            cin >> b[i];
            assert(0 <= b[i] && b[i] <= (int)1e9);
            mxb = max(mxb,b[i]);
        }
        if(mxa == mxb)
        {
            cout << "Tie" << endl;
        }
        else if(mxa < mxb)
        {
            cout << "Alice" << endl;
        }
        else
        {
            cout << "Bob" << endl;
        }
    }
    return 0;
}