fork download
  1. #include <stdio.h>
  2.  
  3. int diwaliContest(int N, int P) {
  4. int totalMinutes = 4 * 60;
  5. int travelTime = P;
  6. int timeLeft = totalMinutes - travelTime;
  7. int solvedProblems = 0;
  8. int timeNeeded = 0;
  9.  
  10. for (int i = 1; i <= N; i++) {
  11. timeNeeded = 5 * i;
  12. if (timeNeeded <= timeLeft) {
  13. solvedProblems++;
  14. timeLeft -= timeNeeded;
  15. } else {
  16. break;
  17. }
  18. }
  19.  
  20. return solvedProblems;
  21. }
  22.  
  23. int main() {
  24. int N, P;
  25. printf("Enter the total number of problems: ");
  26. scanf("%d", &N);
  27. printf("Enter the time to travel (in minutes): ");
  28. scanf("%d", &P);
  29.  
  30. int result = diwaliContest(N, P);
  31. printf("Max can solve %d problems and reach the party venue within the given time frame.\n", result);
  32.  
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
Enter the total number of problems: Enter the time to travel (in minutes): Max can solve 0 problems and reach the party venue within the given time frame.