#include #include using namespace std; struct machine{ int usage; int recovery; }; int main(){ vector jim(10); for(int i = 0; i < 10; i++){ cin >> jim[i].usage; cin >> jim[i].recovery; } vector others(10); vector starts(10); for(int i = 0; i < 10; i++){ cin >> others[i].usage; cin >> others[i].recovery; cin >> starts[i]; } int cur_time = 0; for(int j = 0; j < 3; j++){ for(int i = 0; i < 10; i++){ // jim is at machine i int circuit = others[i].usage + others[i].recovery; int offset = (cur_time-starts[i])%circuit; // how far into the circuit does jim arrive? // cout << "Starting machine "<< i << " "<< offset << " into the other person's cycle" << endl; if(cur_time >= starts[i]) starts[i] = cur_time-offset; // the start of this cycle // this is nice jim. rudejim needs a case where offset==0 if(cur_time >= starts[i] && offset < others[i].usage){ // Then jim must wait. cur_time = cur_time + (others[i].usage-offset); // cout << "Jim waits till " << cur_time << endl; } // so jim uses the machine at "cur_time". He'll be done at // cur_time + usage[i]. We need to know how much that makes // the other person wait int jims_done = cur_time + jim[i].usage; if(jims_done > starts[i] + circuit){ starts[i] = jims_done; // cout << "Start time of " << i << " changed to " << starts[i] << endl; } else if(cur_time < starts[i] && jims_done >= starts[i]){ starts[i] = jims_done; // cout << "Start time of " << i << " changed to " << starts[i] << endl; } /* int new_offset = ((cur_time+jim[i].usage) - starts[i])%circuit; if(new_offset > 0 && new_offset < others[i].usage){ starts[i] = starts[i] + new_offset; cout << "Start time of " << i << "changed to " << starts[i] << endl; } */ cur_time = cur_time + jim[i].usage + jim[i].recovery; // cout << "Time after machine " << i << ": " << cur_time << endl; } } cur_time = cur_time - jim[9].recovery; // don't count last recovery cout << cur_time << endl; return 0; }