Calculating revenue from roller coaster rides Problem description:


  The task is to calculate the amount of money earned from roller
  coaster rides on any given day.  There is a queue in front of the
  attraction.  Visitors might be alone or in groups. All members of
  the same group will want to ride together.  The ride begins once
  the roller coaster runs out of sufficient space for the next group.
   Once a ride is over, passengers go back to the end of the queue
  in the same order.
  Each passenger pays one dirham to ride the roller coaster once.
  The roller coaster can only operate a limited number of times each day.


Here is my code:

public static class RollerCoaster
{
    private static int CountDirhamsEarnedInOneOperation(int numAvailablePlaces, LinkedList&lt;int&gt; numPeopleInEachGroup)
    {
        //Each passenger pays one dirham to take the ride once.
        int dirhamsEarned = 0;
        int numGroupsInQueue = numPeopleInEachGroup.Count();

        while (numPeopleInEachGroup.First() &lt;= numAvailablePlaces &amp;&amp; numGroupsInQueue &gt; 0)
        {
            dirhamsEarned += numPeopleInEachGroup.First();
            numAvailablePlaces -= numPeopleInEachGroup.First();
            numPeopleInEachGroup.AddLast(numPeopleInEachGroup.First()); 
            numPeopleInEachGroup.RemoveFirst();
            numGroupsInQueue--;
        }

        return dirhamsEarned;
    }

    public static long CalculateDirhamsEarned(int numAvailablePlaces, int numOperationsPerDay, LinkedList&lt;int&gt; numPeopleInEachGroup)
    {
        long dirhamsEarned = 0;

        while (numOperationsPerDay &gt; 0)
        {
            dirhamsEarned += (long)CountDirhamsEarnedInOneOperation(numAvailablePlaces, numPeopleInEachGroup);
            numOperationsPerDay--;
        }

        return dirhamsEarned;
    }
}

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Please enter:\nThe number of places available;\nThe number of times the attraction can function per day;\nThe number of groups in the queue.");
        string[] inputs = Console.ReadLine().Split(' ');

        int numAvailablePlaces = int.Parse(inputs[0]);
        int numOperationsPerDay = int.Parse(inputs[1]);
        int numGroupsInQueue = int.Parse(inputs[2]);
        LinkedList&lt;int&gt; numPeopleInEachGroup = new LinkedList&lt;int&gt;();

        Console.WriteLine("Please enter, line by line, the number of people in each group: ");
        for (int i = 0; i &lt; numGroupsInQueue; i++)
        {
            int numPeopleInGroup = int.Parse(Console.ReadLine());
            numPeopleInEachGroup.AddLast(numPeopleInGroup);
        }

        long dirhamsEarned = RollerCoaster.CalculateDirhamsEarned(numAvailablePlaces, numOperationsPerDay, numPeopleInEachGroup);
        Console.WriteLine(dirhamsEarned.ToString());
    }
}


I'm a C# beginner, so I'd appreciate any kind of advice, though I am specifically looking for suggestions that help me improve the time-complexity of my algorithm. My program takes way too long to run when numOperationsPerDay is, say, 10,000,000.
One of the suggestions I would make is to improve your input handling. You don't handle invalid integers well at all.

string input = "invalid int";
int numAvailablePlaces = 0;

while (!int.TryParse(input, out numAvailablePlaces))
{
    Console.WriteLine("Please enter a valid integer for the number of places available.");
    input = Console.ReadLine();
}


And similarly for the other int's you grab. (You could also do them all in one loop.)



This method:


private static int CountDirhamsEarnedInOneOperation(int numAvailablePlaces, LinkedList&lt;int&gt; numPeopleInEachGroup)
{
    //Each passenger pays one dirham to take the ride once.
    int dirhamsEarned = 0;
    int numGroupsInQueue = numPeopleInEachGroup.Count();

    while (numPeopleInEachGroup.First() &lt;= numAvailablePlaces &amp;&amp; numGroupsInQueue &gt; 0)
    {
        dirhamsEarned += numPeopleInEachGroup.First();
        numAvailablePlaces -= numPeopleInEachGroup.First();
        numPeopleInEachGroup.AddLast(numPeopleInEachGroup.First()); 
        numPeopleInEachGroup.RemoveFirst();
        numGroupsInQueue--;
    }

    return dirhamsEarned;
}



Does too much. Break the inside of that while loop to a new method.



Other than that, there's little to say in my opinion.