Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
1.5 kB
2
Indexable
Never
#include<stdio.h>

char findelem(long long int num, long long int size,long long int array[size+1]){
    for (int i = 0; i < (size+1); i++)
        if(num==array[i])
            return 'y';
    return 'n';
}

int main(){
    int N, M, k, count=0,i=0,j=0;
    char check;
    scanf("%d %d %d",&N, &M, &k);
    long long int prefarr[N], availarr[M], checkarr[M*N];
    for ( i = 0; i < (N-1) ; i++)
        scanf("%lld ",&prefarr[i]);
    scanf("%lld",&prefarr[N-1]);
    for ( i = 0; i < (M-1) ; i++)
        scanf("%lld ",&availarr[i]);
    scanf("%lld",&availarr[M-1]);
    for ( i = 0; i < N; ++i) 
        for ( j = i + 1; j < N; ++j)
            if (prefarr[i] > prefarr[j]) 
            {
                long long int a =  prefarr[i];
                prefarr[i] = prefarr[j];
                prefarr[j] = a;
            }
    for ( i = 0; i < M; ++i) 
        for ( j = i + 1; j < M; ++j)
            if (availarr[i] > availarr[j]) 
            {
                long long int a =  availarr[i];
                availarr[i] = availarr[j];
                availarr[j] = a;
            }
    for (i = 0; i < M; i++)
        for ( j = 0; j < N; j++){
            check = findelem(prefarr[j], count, checkarr);
            if ((availarr[i] >= prefarr[j]-k)&&
            (availarr[i] <= prefarr[j]+k)&&
            check == 'n'){
                checkarr[count] = prefarr[j];
                count++;
                break;
            }
        }
    printf("%d",count);
    return 0;
}