Make the intervals non | C ++ implementation for intervals scheduling to two processors such that there are no overlapping intervals ; Function to assign the intervals to two different processors ; Loop to pair the interval with their indices ; sorting the interval by their start times ; Loop to iterate over the intervals with their start time ; Condition to check if there is a possible solution ; form = ''.join(form) ; Driver Code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void assignIntervals ( vector < vector < int > > interval , int n ) { for ( int i = 0 ; i < n ; i ++ ) interval [ i ] . push_back ( i ) ; sort ( interval . begin ( ) , interval . end ( ) ) ; int firstEndTime = -1 ; int secondEndTime = -1 ; char fin = ' ▁ ' ; bool flag = false ; for ( int i = 0 ; i < n ; i ++ ) { if ( interval [ i ] [ 0 ] >= firstEndTime ) { firstEndTime = interval [ i ] [ 1 ] ; interval [ i ] . push_back ( ' S ' ) ; } else if ( interval [ i ] [ 0 ] >= secondEndTime ) { secondEndTime = interval [ i ] [ 1 ] ; interval [ i ] . push_back ( ' F ' ) ; } else { flag = true ; break ; } } if ( flag ) cout << ( -1 ) ; else { vector < char > form ( n , ' ▁ ' ) ; for ( int i = 0 ; i < n ; i ++ ) { int indi = interval [ i ] [ 2 ] ; form [ indi ] = interval [ i ] [ 3 ] ; } for ( int i = 0 ; i < form . size ( ) ; i ++ ) cout << form [ i ] << " , " ; } } int main ( ) { vector < vector < int > > intervals = { { 360 , 480 } , { 420 , 540 } , { 600 , 660 } } ; assignIntervals ( intervals , intervals . size ( ) ) ; return 0 ; }