Search This Blog

Tuesday 23 August 2016

SPOJ - He is Offside Problem Solution without sorting

SPOJ - He is Offside Problem Solution without sorting

Solution:-

#include<bits/stdc++.h>
using namespace std;

int attacker,defender,goalie;

int main()
{
    int a,d;
    while(1)
    {
        attacker=defender=goalie=INT_MAX;
        cin>>a>>d;
        if(a==0 && d==0)
            break;
        int temp;
        for(int i=0;i<a;i++)
        {
            cin>>temp;
            if(temp<attacker)
                attacker=temp;
        }

        for(int i=0;i<d;i++)
        {
            cin>>temp;
            if(temp<goalie)
            {
                defender=goalie;
                goalie=temp;
            }
            else if(temp<defender)
                defender=temp;
        }

        if(defender>attacker)
            cout<<"Y\n";
        else
            cout<<"N\n";
    }
    return 0;

}

No comments:

Post a Comment