/// Reference : https://algorithmsandme.com/interval-partitioning-problem/
/// Reference : https://bit.ly/37SyI7L
/// Reference : https://www.youtube.com/watch?v=i_G8hZYcKnI
using namespace std;
int interval(vector<int>st, vector<int>ft, int n)
{
int i = 1, j = 0, dorker = 1, r = 1;
while(i < n && j < n)
{
if(st[i] < ft[j])
{
dorker++;
i++;
if(dorker > r)
{
r = dorker;
}
}
else
{
dorker--;
j++;
}
}
return r;
}
int main()
{
int n, i;
cout << "Enter Schedule Number :: ";
cin >> n;
vector<int>start(n), finish(n);
cout << "\nEnter Start And Finish Time :: \n";
for(i=0;i<n;i++)
{
cin >> start[i] >> finish[i];
}
sort(start.begin(), start.end());
sort(finish.begin(), finish.end());
cout << "\nTotal Class Required :: " << interval(start, finish, n) << "\n";
return 0;
}
Comments
Post a Comment