Friday 21 July 2017

SPOJ : OFFSIDE Solution



#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<iostream>
#define LL long long
#define mx 10010
using namespace std;

int main()
{
    int n,i;
    int a,b;
    scanf("%d%d",&a,&b);
    while(a!=0 || b!=0)
      {
          int small=mx;
          while(a--)
          {scanf("%d",&i);if(i<small)small=i;}

          int sm1=mx,sm2=mx,pos=0;
          int k[b];
          for(i=0;i<b;i++)
          {
              scanf("%d",&k[i]);
              if(k[i]<sm1) sm1=k[i],pos=i;
          }
          for(i=0;i<b;i++)
          {
              if(k[i]<=sm2 && k[i]>=sm1 && i!=pos) sm2=k[i];
          }

          //printf("%d %d %d\n",small,sm1,sm2);

          if(small==sm2 || (small==sm2 && small==sm1))
            printf("N\n");
          else
          {if(small<sm2)
            printf("Y\n");
            else printf("N\n");
          }

            scanf("%d%d",&a,&b);
      }

    return 0;
}

Question at: OFFSIDE - He is offside!
Find smallest element in the ist array , this will be the last player closest to goal line.Then find the smallest and second smallest element as sm1 and sm2 in 2nd array , this will be the last and second last player of opponent team, then apply offside and not offside rule as given in question.

No comments:

Post a Comment

SPOJ : MARBLES Solution

Question  MARBLES - Marbles Explaination.... Fill n spaces , with k colors. First select k spaces with k-different color.  Now we are l...