I am trying to solve a problem, but unfortunately my solution is not very suitable for this task.
Task:
There are N guests at the party (0 <N <30,000). All guests tell when they get to the party and when they leave (for example, [10; 12]). The challenge is to photograph as many people as possible at the party. There can only be 2 people (couple) in the photo, and each person can only be in one photo. Of course, a photograph can only be taken when both participants are at a party. This is the case when the intervals of their visits overlap.
My idea: I wrote a program that creates a connection schedule from intervals. On the graph, I am looking for the person with the least number of connections. From the connected persons, I also choose the person with the smallest connections. Then these two are selected as a pair in the photo. Both of them are removed from the chart. The algorithm runs until the connections are deleted.
This approach works, but there is a 10 second limit to program calculation. With 1000 records, it works after 2 seconds, but even with 4000 it takes a lot of time. In addition, when I tried it with 25,000 data, the program stops with an out-of-memory error, so I canβt even save the connections correctly.
I think a new approach is needed here, but I could not find another way to do this work.
Can someone help me find the right algorithm for this task?
Thank you very much!
Sample data:
10 1 100 2 92 3 83 4 74 5 65 6 55 7 44 8 33 9 22 10 11
The first line is the number of guests, the additional data is the intervals of people on the side.
source share