. 1 // EG input 100. 5 2 // P1 150 . 3 // P2 80 . 4 // P3 200 is . 5 // P4 350 . 6 // P5 20 is . 7 #include <the iostream> . 8 #include < String > . 9 #include <Queue> 10 the using namespace STD; . 11 int main () { 12 is int n-; // number of tasks 13 is int time; // time slice 14 CIN >> n-; 15 >> CIN Time; 16 String P [ 100000 ]; // task name . 17 int T [ 100000 ]; 18 is String PP; . 19 Queue < String > Q; 20 is for ( int I = . 1 ; I <= n-; I ++) { // input, and when each task with 21 is CIN >> P [I]; 22 is q.push (P [I]); 23 is CIN >> T [I]; 24 } 25 int timeans = 0 ; // timer 26 is the while (! {Q.empty ()) 27 PP = q.front (); 28 IF (T [PP [ . 1 ] - ' 0 ' ] <= Time) { // takes less time slice 29 timeans = + T timeans [PP [ . 1 ] - ' 0 ' ]; // timer plus the time 30 q.pop (); // after completion dequeue 31 is COUT << << PP ' ' << timeans < < endl; 32 } 33 is the else { // Processed time slice is greater than 34 + Time = timeans timeans; // timer plus the time 35 T [PP [ . 1 ] - ' 0 ' ] - = Time; // update with this task 36 q.pop (); // dequeue 37 [ q.push (PP); 38 is } 39 } 40 return 0 ; 41 is }