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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 #include #include #include #include #include #include #include using namespace std; template void write_vector(const vector& v) { cout << "The numbers in the vector are: " << endl; std::copy(v.begin(), v.end(), std::ostream_iterator(std::cout, " ")); } unsigned long long GetWaitingTime(vector v_t, int d) //czas przyjscia, czas pieczenia { unsigned long long sum = 0; unsigned long long last_output; if (v_t[0] < d) { sum += d - v_t[0]; last_output = v_t[0] + sum; } else { last_output = v_t[0]; } for (int i = 1; i < v_t.size(); i++) { if (v_t[i] > last_output) { if (v_t[i] - last_output >= d) { last_output = v_t[i]; } else { sum += d - (v_t[i] - last_output); last_output = v_t[i] + (d - (v_t[i] - last_output)); } } else if(v_t[i] == last_output) { sum += d; last_output = v_t[i] + d; } else { sum += (last_output - v_t[i]) + d; last_output = last_output + d; } } return sum; } int main() { int n, k; cin >> n >> k; vector lines; string line; short counter = 0; while (counter < 2 && getline(cin >> ws, line)) { if (!line.empty()) { lines.push_back(line); counter++; } } unsigned long long t; vector v_t; stringstream visit_times(lines[0]); while (visit_times >> t) v_t.push_back(t); int d; vector v_d; stringstream baking_times(lines[1]); while (baking_times >> d) v_d.push_back(d); vector waiting_times; for (int i = 0; i < v_d.size(); i++) { waiting_times.push_back(GetWaitingTime(v_t, v_d[i])); } cout << waiting_times[0]; for (int i = 1; i < waiting_times.size(); i++) { cout << "\n" << waiting_times[i]; } }