// Zapiekanki2.cpp : Defines the entry point for the console application. // #include <iostream> #include <vector> int main() { std::ios_base::sync_with_stdio(0); unsigned int clientCounter, ovenCounter; std::cin >> clientCounter >> ovenCounter; std::vector<unsigned int> clientTimestamp(clientCounter); for (auto i = 0u; i < clientCounter; ++i) { std::cin >> clientTimestamp[i]; } auto ovenTime = 0u; for (auto i = 0u; i < ovenCounter; ++i) { std::cin >> ovenTime; long long currentTime = 0; long long waitingTime = 0; for (auto j = 0u; j < clientCounter; ++j) { if (currentTime + ovenTime <= clientTimestamp[j]) { currentTime = clientTimestamp[j]; } else { currentTime += ovenTime; waitingTime += currentTime - clientTimestamp[j]; } } std::cout << waitingTime << std::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 41 42 43 44 | // Zapiekanki2.cpp : Defines the entry point for the console application. // #include <iostream> #include <vector> int main() { std::ios_base::sync_with_stdio(0); unsigned int clientCounter, ovenCounter; std::cin >> clientCounter >> ovenCounter; std::vector<unsigned int> clientTimestamp(clientCounter); for (auto i = 0u; i < clientCounter; ++i) { std::cin >> clientTimestamp[i]; } auto ovenTime = 0u; for (auto i = 0u; i < ovenCounter; ++i) { std::cin >> ovenTime; long long currentTime = 0; long long waitingTime = 0; for (auto j = 0u; j < clientCounter; ++j) { if (currentTime + ovenTime <= clientTimestamp[j]) { currentTime = clientTimestamp[j]; } else { currentTime += ovenTime; waitingTime += currentTime - clientTimestamp[j]; } } std::cout << waitingTime << std::endl; } return 0; } |