SHARE
TWEET

Untitled

a guest May 19th, 2019 66 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 max=-1;
  33.     for(i=1;i<=1000001;i++){
  34.         if(aux[i]>=counter-1&&aux[i]>max){
  35.             max = i;
  36.         }
  37.     }
  38.     printf("%d\n",max);
  39.  
  40.     return 0;
  41. }
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