We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- C++
- Other Concepts
- Attending Workshops
- Discussions
Attending Workshops
Attending Workshops
Sort by
recency
|
186 Discussions
|
Please Login in order to post a comment
//try this
include
include
include
using namespace std;
class Workshop { public: int start_time; int end_time;
};
class Available_Workshops { public: vector workshops;
};
Available_Workshops* initialize(int start_time[], int duration[], int n) { vector workshops; for (int i = 0; i < n; i++) { workshops.push_back(Workshop(start_time[i], duration[i])); } Available_Workshops* available_workshops = new Available_Workshops(workshops); return available_workshops; }
int CalculateMaxWorkshops(Available_Workshops* ptr) { vector& workshops = ptr->workshops;
}
int main() { int n; // Number of workshops cin >> n;
}
I just tried a new solution in C++. I found that using a deque with workshops sorted by start time and duration is more convenient. First, store all workshops inside that deque, sort them, and then use a helper deque to get the maximum number of workshops with no overlap. The trick is to take the workshop with the earliest end time if they overlap. My code works and passed all tests successfully; however, it can be further improved.
Earliest Finish Time Greedy Algorithm