Итак, вот как это выглядит в VBA:
Option Explicit
Sub UsingArrayList()
Dim sht As Worksheet
Dim FirstRow, LastRow As Long
Set sht = ActiveSheet
Dim arrival As Object, departure As Object
Dim i As Long, j As Long, n As Long
Dim guests_in As Long, max_guests As Long, time As Double
Set arrival = CreateObject("System.Collections.ArrayList")
Set departure = CreateObject("System.Collections.ArrayList")
With sht
' Copy ranges into arrival and departure arrays
FirstRow = 2
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = FirstRow To LastRow
arrival.Add (.Cells(i, 1).Value)
departure.Add (.Cells(i, 2).Value)
Next i
End With
' Sort arrival and departure arrays
arrival.Sort
departure.Sort
' guests_in indicates number of guests at a time
guests_in = 1
max_guests = 1
time = arrival.Item(0)
i = 1
j = 0
n = arrival.Count
' Similar to merge in merge sort to process
' all events in sorted order
While (i < n And j < n)
' If next event in sorted order is arrival,
' increment count of guests
If (arrival.Item(i) <= departure.Item(j)) Then
guests_in = guests_in + 1
' Update max_guests if needed
If (guests_in > max_guests) Then
max_guests = guests_in
time = arrival.Item(i)
End If
i = i + 1 'increment index of arrival array
Else ' If event is departure, decrement count
' of guests.
guests_in = guests_in - 1
j = j + 1
End If
Wend
Debug.Print ("Max concurrency=" & max_guests)
Debug.Print ("at time " & time)
Debug.Print ("at time " & Application.Text(time, "hh:mm:ss"))
End Sub
Если я запускаю его на предоставленных тестовых данных здесь Я получу ожидаемый ответ 3 для параллелизма при 5 o 'clock.
Если я запускаю его на вашей выборке из 9 строк данных, я получаю параллелизм 9 в 7:14:41 - потому что все периоды времени в выборке перекрываются.
Я попытался запустить его для полного столбца данных, и это занимает 2-3 минуты.