#include <iostream> #include <vector> int main() { // initialization int numberOfSpeciec = 0; std::cin >> numberOfSpeciec; int numberOfMowing = 0; std::cin >> numberOfMowing; std::vector<int> vectorOfSpeeds; std::vector<int> vectorOfHigh; for (int i=0; i<numberOfSpeciec; i++) { int speed = 0; std::cin >> speed; vectorOfSpeeds.push_back(speed); vectorOfHigh.push_back(speed); } std::vector<int> vectorOfMowings; for (int i=0; i<numberOfMowing; i++) { int mowing = 0; int trash; std::cin >> trash >> mowing; vectorOfMowings.push_back(mowing); } // simulation for (int i=0; i<numberOfMowing; i++) { int sumOfKilograms = 0; for (int j=0; j<numberOfSpeciec; j++) { int diff = vectorOfHigh[j] - vectorOfMowings[i]; if (diff > 0) { sumOfKilograms += diff; vectorOfHigh[j] = vectorOfMowings[i]; } vectorOfHigh[j] += vectorOfSpeeds[j]; } std::cout << sumOfKilograms << 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 45 46 47 | #include <iostream> #include <vector> int main() { // initialization int numberOfSpeciec = 0; std::cin >> numberOfSpeciec; int numberOfMowing = 0; std::cin >> numberOfMowing; std::vector<int> vectorOfSpeeds; std::vector<int> vectorOfHigh; for (int i=0; i<numberOfSpeciec; i++) { int speed = 0; std::cin >> speed; vectorOfSpeeds.push_back(speed); vectorOfHigh.push_back(speed); } std::vector<int> vectorOfMowings; for (int i=0; i<numberOfMowing; i++) { int mowing = 0; int trash; std::cin >> trash >> mowing; vectorOfMowings.push_back(mowing); } // simulation for (int i=0; i<numberOfMowing; i++) { int sumOfKilograms = 0; for (int j=0; j<numberOfSpeciec; j++) { int diff = vectorOfHigh[j] - vectorOfMowings[i]; if (diff > 0) { sumOfKilograms += diff; vectorOfHigh[j] = vectorOfMowings[i]; } vectorOfHigh[j] += vectorOfSpeeds[j]; } std::cout << sumOfKilograms << std::endl; } return 0; } |