Maximum Guests on a Cruise

Problem - Maximum Guests on a Cruise

A party has been organised on a cruise for a limited time (T). The number of guests entering (E[i]) and leaving (L[i]) the party at every hour is represented as elements of the array. The task is to find the maximum number of guests present on the cruise at any given instance within T hours.

Constraints:
  • 1 <= T <= 25
  • 0 <= E[i] <= 500
  • 0 <= L[i] <= 500

Example 1

Input:

5 -> Value of T
[7, 0, 5, 1, 3] -> E[], elements separated by new line
[1, 2, 1, 3, 4] -> L[], elements separated by new line

Output:
8 -> Maximum number of guests on cruise at an instance.

Example 2

Input:

4 -> Value of T
[3, 5, 2, 0] -> E[], elements separated by new line
[0, 2, 4, 4] -> L[], elements separated by new line

Output:
6 -> Maximum number of guests on cruise at an instance.

Solution in:

#include<stdio.h>
#include<math.h>
int main(){
    int t;
    scanf("%d",&t);
    int entries[t], exits[t];
    for(int i=0;i<t;i++){
        scanf("%d",&entries[i]);
    }
    int max = 0, totalIn = 0;
    for(int i=0;i<t;i++){
        scanf("%d",&exits[i]);
        totalIn += entries[i] - exits[i];
        max = (int)fmax(max, totalIn);
    }
    printf("%d", max);
    return 0;
}