Question
C Programming Lanuage The code below runs, but runs into a time limit error. Can someone modify the code so it runs more efficiently? #include
C Programming Lanuage
The code below runs, but runs into a time limit error. Can someone modify the code so it runs more efficiently?
#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 sortArr(int n, int arr[]) //sort array { int temp; for(int i = 0; i int detPeople(int power, int arr[], int n) { int count = 0; for(int i = 0; i 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); sortArr(n, arr); //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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started