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.
int taskScheduling(int d, int m) {
// Read d task descriptions
vector> tasks;
for (int i = 0; i < d; i++) {
int duration, deadline;
cin >> duration >> deadline;
tasks.push_back({duration, deadline});
}
// Sort tasks by deadline (Earliest Deadline First)
sort(tasks.begin(), tasks.end(), [](const pair<int, int>& a, const pair<int, int>& b) {
return a.second < b.second;
});
int currentTime = 0;
int maxLateness = 0;
// Schedule each task and compute maximum lateness
for (auto& task : tasks) {
int duration = task.first;
int deadline = task.second;
currentTime += duration;
int lateness = max(0, currentTime - deadline);
maxLateness = max(maxLateness, lateness);
}
return maxLateness;
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Task Scheduling
You are viewing a single comment's thread. Return to all comments →
Check mobile phone prices qatar for more information.
int taskScheduling(int d, int m) { // Read d task descriptions vector> tasks; for (int i = 0; i < d; i++) { int duration, deadline; cin >> duration >> deadline; tasks.push_back({duration, deadline}); }
}