Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

W/A IN COUNT OF MAX (EASY) MAXCOUNT

$
0
0

include<stdio.h>

int main() { int i, t, n;

scanf("%d", &t);

while (t--)
{
    int a[10010], max = 0, ctr = 0, pos=0, k, x;
    scanf("%d", &n);
    for (i = 0; i < 10010; i++)
        a[i] = 0;

    for (i = 0; i < n; i++)
    {
        scanf("%d", &x);
        a[x - 1]++;

        if (max < x)
        {
            max = x;
        }
    }
    for (i = 0; i < max; i++)
    if (a[i]!=0)
    {
        if (ctr < a[i])
        {
            ctr = a[i];
            pos = i;
        }

        if (ctr == a[i])
        {
            if (pos>i)
            {
                pos = i;
            }
        }
    }
    pos++;
    printf("%d %d", pos++, ctr);
}

return 0;

}


Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>