# TÓPICO

WRONG 10%. Where did I go wrong? I have no idea.

#### Vanderlei Ribeiro Santana perguntou 2 anos atrás

```#include <stdio.h>
#include <stdlib.h>

void merge(int A[], int l, int m, int r){
int i, j, k;
int n1 = m - l + 1;
int n2 =  r - m;

int L[n1], R[n2];

for (i = 0; i < n1; i++)
L[i] = A[l + i];
for (j = 0; j < n2; j++)
R[j] = A[m + 1 + j];

i = 0;
j = 0;
k = l;

while (i < n1 && j < n2){
if (L[i] <= R[j]){
A[k] = L[i];
i++;
}
else{
A[k] = R[j];
j++;
}
k++;
}

while (i < n1){
A[k] = L[i];
i++;
k++;
}

while (j < n2){
A[k] = R[j];
j++;
k++;
}
}

void mergeSort(int A[], int l, int r){
if (l < r){

int m = l+(r-l)/2;

mergeSort(A, l, m);
mergeSort(A, m+1, r);

merge(A, l, m, r);
}
}

int main(){

int N, Q, cases = 0;
int i, j;

for(i = 0; i < 64 ; i++){

scanf("%d%d", &N, &Q);
while(N < 0 || Q < 0 || N > 10000 || Q > 10000){
printf("Invalid values, try again ");
scanf("%d%d", &N, &Q);
}

if(N == 0 && Q == 0)
return 0;

cases++;
int *A= malloc(N * sizeof(int));
int *B= malloc(Q * sizeof(int));

for(j = 0 ; j < N ; j++){
scanf("%d", &A[j]);
if(A[j] < 0 || A[j] > 10000){
printf("Invalid value, try again ");
j--;
}
}

for(j = 0 ; j < Q ; j++){
scanf("%d", &B[j]);
if(B[j] < 0 || B[j] > 10000){
printf("Invalid value, try again ");
j--;
}
}

mergeSort(A, 0, N-1);
mergeSort(B, 0, Q-1);

printf("CASE# %d:\n", cases);

for(i = 0 ; i < Q ; i++){
for(j = 0 ; j < N ; j++){
if(A[j] == B[i]){
printf("%d found at %d\n", B[i], j + 1);
break;
}

if(j == N-1)