Question: C Programming Language In this problem, linear searching is not enough. I need to use more efficient methods like binary search and quick sort to

C Programming Language

C Programming Language In this problem, linear searching is not enough. I

In this problem, linear searching is not enough. I need to use more efficient methods like binary search and quick sort to solve because of the time limit. This is my code so far, the sorting does not work. Please correct the code or offer your own solution.

#include

void inArr(int n, int arr[]) //initialize array { for(int i = 0; i

}

void printArr(int n, int arr[]) //print array { for(int q = 0; q

void swap(int* a, int* b) { int t = *a; *a = *b; *b = t; } int partition (int arr[], int low, int high) { int pivot = arr[high]; // pivot int i = (low - 1); // Index of smaller element for (int j = low; j

if (arr[j]

void quickSort(int arr[], int low, int high) { if (low search) first = middle - 1; else if (array[middle]

int main() { int n; /umber of people int q; /umber of questions scanf("%d %d", &n, &q); int arr[120000]; //contains the people inArr(n, arr); quickSort(arr, 0, n-1); printArr(n, arr); int ele; /umber of people to kill int pow; //power needed to kill;

for(int i = 0; i An evil dragon just wakes up from his slumber, he is so powerful that if he uses all his might, all the kingdom will perish. Of course, he won't do it because he wants to toy with mankind first. He knows that if he uses Y power, then al life Y meter around him will turn to dust in an instant. He wonders how much power should he use, then he offers you that he will spare you if you help him to calculate how many life will fall victim to his power. Because you don't want to die, you choose to help him. Format Input The first line will contain N and M, each denoting the number of people in the surrounding area and the number of question that the dragon will ask. The next line will consist of N integers a, each denoting the distance between them and the dragon. The next M lines consist of an integer Y, denoting the dragon's question "If I use Y power, how many people will fall victim?" Format Output For each question, print the answer of the dragon's question Constraints 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!