#include <iostream> #include <vector> using namespace std; int main() { int cNumber = 0; int pNumber = 0; std::cin >> cNumber; std::cin >> pNumber; vector<long long> cTimes(cNumber); for (int i = 0; i < cNumber; i++){ std::cin >> cTimes[i]; } vector<long long> pVelocity(pNumber); for (int i = 0; i < pNumber; i++){ std::cin >> pVelocity[i]; long long curentVelocity = pVelocity[i]; int total = 0; int nextReady = curentVelocity; for (int j = 0; j < cNumber; j++){ long long currentTime = cTimes[j]; if (currentTime < nextReady) { total += nextReady - currentTime; nextReady += curentVelocity; } else { nextReady = currentTime + curentVelocity; } } std::cout << total << 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> using namespace std; int main() { int cNumber = 0; int pNumber = 0; std::cin >> cNumber; std::cin >> pNumber; vector<long long> cTimes(cNumber); for (int i = 0; i < cNumber; i++){ std::cin >> cTimes[i]; } vector<long long> pVelocity(pNumber); for (int i = 0; i < pNumber; i++){ std::cin >> pVelocity[i]; long long curentVelocity = pVelocity[i]; int total = 0; int nextReady = curentVelocity; for (int j = 0; j < cNumber; j++){ long long currentTime = cTimes[j]; if (currentTime < nextReady) { total += nextReady - currentTime; nextReady += curentVelocity; } else { nextReady = currentTime + curentVelocity; } } std::cout << total << endl; } return 0; } |