SHARE
TWEET

Untitled

a guest May 19th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5.  
  6. int main(int argc, char const *argv[])
  7. {
  8.     int n, A;
  9.     scanf("%d %d",&n,&A);
  10.  
  11.     int *aux = (int*)malloc(sizeof(int)*1000001);
  12.     int i,color;
  13.  
  14.     for(i=0;i<=1000001;i++)
  15.         aux[i] = -1;
  16.  
  17.     int counter=0;
  18.  
  19.     for(i=1;i<=n;i++)
  20.     {
  21.         scanf("%d",&color);
  22.         if(color==A) counter++;
  23.         else {
  24.             if(aux[color]>=counter-1){
  25.                 aux[color]++;
  26.             }
  27.             else{
  28.                 aux[color] = -2;
  29.             }
  30.         }
  31.     }
  32.     int ok=1;
  33.     for(i=1;i<=1000001;i++){
  34.         if(aux[i]>counter-1){
  35.             printf("%d\n",i);
  36.             ok=0;
  37.             break;
  38.         }
  39.     }
  40.     if(ok==1) printf("-1\n");
  41.     return 0;
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top