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