Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
555 B
1
Indexable
Never
#include<stdio.h>

void nhap(int *a, int n)
{
    int i;
    for(i = 0;i<n;i++)
    {
        scanf("%d", &a[i]);
    }
}

int max(int a, int b)
{
    if(a>=b)
    {
        return a;
    }
    return b;
}

int main()
{
     int n,m;
    scanf("%d%d", &n, &m);
    int a[n];
    int b[m];
    nhap(a,n);
    nhap(b,m);
    int f[n];
    f[0] = a[0];
    int i;
    for(i = 1;i<=n;i++)
    {
        f[i] = max(f[i-1],a[i]);
    }
    for(i = 0;i<m;i++)
    {
        printf("%d\n", f[b[i]-1]);
    }
    return 0;
}