#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { long num_of_clients; long num_of_ovens; vector<long> clients; vector<long> ovens; cin >> num_of_clients >> num_of_ovens; long temp; for (long i = 0; i < num_of_clients; i++) { cin >> temp; clients.push_back(temp); } for (long i = 0; i < num_of_ovens; i++) { cin >> temp; ovens.push_back(temp); } for (long i = 0; i < num_of_ovens; i++) { long bake_time = ovens.at(i); long wait_time = 0; long first_free_time = 0; for(long j = 0; j < num_of_clients; j++) { long arive_time = clients.at(j); if (j == 0) { wait_time = max(0L, bake_time - arive_time); first_free_time = max(arive_time, bake_time); } else { wait_time += max(0L, first_free_time + bake_time - arive_time); first_free_time = max(arive_time, first_free_time + bake_time); } } cout << wait_time << endl; } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { long num_of_clients; long num_of_ovens; vector<long> clients; vector<long> ovens; cin >> num_of_clients >> num_of_ovens; long temp; for (long i = 0; i < num_of_clients; i++) { cin >> temp; clients.push_back(temp); } for (long i = 0; i < num_of_ovens; i++) { cin >> temp; ovens.push_back(temp); } for (long i = 0; i < num_of_ovens; i++) { long bake_time = ovens.at(i); long wait_time = 0; long first_free_time = 0; for(long j = 0; j < num_of_clients; j++) { long arive_time = clients.at(j); if (j == 0) { wait_time = max(0L, bake_time - arive_time); first_free_time = max(arive_time, bake_time); } else { wait_time += max(0L, first_free_time + bake_time - arive_time); first_free_time = max(arive_time, first_free_time + bake_time); } } cout << wait_time << endl; } return 0; } |