#include <iostream> #include <algorithm> using namespace std; int main() { int bakerCnt; int clientsCnt; cin >> clientsCnt >> bakerCnt; long long* clientArrival = new long long[clientsCnt]; long long* e = new long long[clientsCnt]; long long* bakeTime = new long long[bakerCnt]; for (int i = 0; i < clientsCnt; i++) { std::cin >> clientArrival[i]; } for (int i = 0; i < bakerCnt; i++) { std::cin >> bakeTime[i]; } long long zero = 0; for (int actualBaker = 0; actualBaker < bakerCnt; actualBaker++) { long long waitTime = 0; e[0] = max(clientArrival[0], bakeTime[actualBaker]); for (int actualCust = 1; actualCust < clientsCnt; actualCust++) { e[actualCust] = max(clientArrival[actualCust], e[actualCust-1] + bakeTime[actualBaker]); waitTime += max(zero, e[actualCust-1] + bakeTime[actualBaker] - clientArrival[actualCust]); } waitTime += max(zero, bakeTime[actualBaker] - clientArrival[0]); std::cout << waitTime << 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 | #include <iostream> #include <algorithm> using namespace std; int main() { int bakerCnt; int clientsCnt; cin >> clientsCnt >> bakerCnt; long long* clientArrival = new long long[clientsCnt]; long long* e = new long long[clientsCnt]; long long* bakeTime = new long long[bakerCnt]; for (int i = 0; i < clientsCnt; i++) { std::cin >> clientArrival[i]; } for (int i = 0; i < bakerCnt; i++) { std::cin >> bakeTime[i]; } long long zero = 0; for (int actualBaker = 0; actualBaker < bakerCnt; actualBaker++) { long long waitTime = 0; e[0] = max(clientArrival[0], bakeTime[actualBaker]); for (int actualCust = 1; actualCust < clientsCnt; actualCust++) { e[actualCust] = max(clientArrival[actualCust], e[actualCust-1] + bakeTime[actualBaker]); waitTime += max(zero, e[actualCust-1] + bakeTime[actualBaker] - clientArrival[actualCust]); } waitTime += max(zero, bakeTime[actualBaker] - clientArrival[0]); std::cout << waitTime << std::endl; } return 0; } |