#include using namespace std; const int MAXM = 10; struct times { int usage; int recovery; int total; int start; }; times jim[MAXM]; times others[MAXM]; int main() { int n = 10; for(int i=0; i> jim[i].usage >> jim[i].recovery; jim[i].total = jim[i].usage + jim[i].recovery; } for(int i=0; i> others[i].usage >> others[i].recovery >> others[i].start; others[i].total = others[i].usage + others[i].recovery; } int t=0; for(int reps = 1; reps <= 3; reps++) { for(int m=0; m= others[m].start && (t-others[m].start)%others[m].total <= others[m].usage) t += others[m].usage - (t-others[m].start)%others[m].total; if (t >= others[m].start) others[m].start = t - (t-others[m].start)%(others[m].total); // update most recent start time for person m //cout << "start machine " << m << " at " << t << ", updated start time for person " << m << " = " << others[m].start << endl; if (others[m].start + others[m].total < t+ jim[m].usage) { others[m].start = t+jim[m].usage; //cout << "person " << m << " start time changed to " << others[m].start << endl; } else if (t < others[m].start && t+jim[m].usage > others[m].start) { others[m].start = t+jim[m].usage; //cout << "person " << m << " start time changed to " << others[m].start << endl; } t += jim[m].total; } } cout << t-jim[n-1].recovery << endl; }