You have got homework in N subjects for each homework you require a minimum of min energy and consume actual energy while doing it.
Example, if for a other home work mini=12 and actuality=10, you require at least 12 energy for starting this homework. If u have 11 energy or less you cannot do this homework.
Calculate the minimum intial energy required to complete all the homework
Note : you can finish the homework in any order you like
Constraints
1<=N<=10^5
1<=actual [i]<=10^3
1<=min[I]<=10^3
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void minimumInitialEnergy(int lower, int upper, int count) {
int Sum = 0;
for (int i = 0; i < count; i++) {
Sum += (rand() % (upper - lower + 1)) + lower;
}
printf("The initial Energy which required for %d subjects is %d", count, Sum);
}
int main() {
int N;
printf("Enter the number of subjects: ");
scanf("%d", &N);
minimumInitialEnergy(1, 1000, N);
return 0;
}
Comments
Leave a comment