The prompt is:
Riverfield Country Day School will be hosting its Prom Night tonight.There would be M boys and N girls at the prom tonight. Each boy wants to dance with a girl who is strictly shorter than him. A girl can dance with only one boy and vice-versa. Given the heights of all the boys and girls tell whether it is possible for all boys to dance with a girl.
Input: The first line contains T denoting the number of test cases. Each test case contains three lines. The first line contains M and N. The second line contains M integers each denoting the height of boy. The third contains N integers each denoting the height of girl.
Output: Print YES if it is possible for each boy to dance with a girl else print NO.
Sample input:
1
4 5
2 5 6 8
3 8 5 1 7
Output from sample input:
YES
The plan with my code is to fill two arrays with the heights of the girls and boys and then to search through each girl with each boy. If the boy's height is greater than the girl at that spot, I want to remove the girl at that index and shift the girl heights array back one and resize it. I changed the code around to fix some syntax errors but now I get a different error and it doesn't output. The issue is I get this error:
Exited with return code -11 (SIGSEGV).
Here is my code:
//Jacob Hathaway September 11, 2022 Sorting
#include <stdio.h>
#include <stdlib.h>
void remove_girl(int**, int, int, int);
int main() {
int j, h, i, g, testCases, numBoys, numGirls, *boyHeights, *girlHeights;
scanf("%d", &testCases);
for (g = 0; g < testCases; g++) { // For each test case
scanf("%d", &numBoys);
scanf("%d", &numGirls);
boyHeights = (int*)malloc(sizeof(int)*numBoys); //Allocating Memory
girlHeights = (int*)malloc(sizeof(int)*numGirls); //Allocating Memory
for(j = 0; j < numBoys; j++){ // Filling Array
scanf("%d", &h);
*(boyHeights+j) = h;
}
for(j = 0; j < numGirls; j++){ // Filling Array
scanf("%d", &h);
*(girlHeights+j) = h;
}
for(j = 0; j < numBoys; j++){ // For each boy
for(i = 0; i < numGirls; i++){ // Go through each girl
if (girlHeights[i] < boyHeights[j]) { //If the height of the girl at position i is less than boy at position j
remove_girl(&girlHeights, i, numGirls, sizeof(girlHeights)); // Call to function that removes the girl at i and shifts
//numGirls -= 1;
}
}
}
if (((int(sizeof(girlHeights)) - int(sizeof(boyHeights))) <= (numGirls - numBoys))) {
printf("YES\n");
}
else {
printf("NO\n");
}
}
free(boyHeights);
free(girlHeights);
return 0;
}
void remove_girl(int **girlHeights, int index, int numGirls, int size) { //removes girl at index and shifts array back
long unsigned int p;
for(p = index; p < sizeof(girlHeights) - 1; p++) girlHeights[p] = girlHeights[p+1];
*girlHeights = (int*)malloc(sizeof(int)*(numGirls-1));
}