#include <iostream> #include <limits> #include <vector> #include <array> using Number = unsigned long; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); Number spieciesCount{0}; std::cin >> spieciesCount; Number mowingCount{0}; std::cin >> mowingCount; const auto N = 500000; Number spieces[N]; Number lawnHeight[N]; //std::array<Number, N> spieces; //std::array<Number, N> lawnHeight; // std::vector<Number> spieces(spieciesCount, 0); // std::vector<Number> lawnHeight(spieciesCount, 0); std::vector<Number> mowns(mowingCount, 0); for (Number i = 0U; i < spieciesCount; ++i) { std::cin >> spieces[i]; lawnHeight[i] = 0; } Number previousDay{0}; Number day{0}; Number cutHeight{0}; Number dayDifference{0}; Number mownWeight{0}; for (auto & mown : mowns) { std::cin >> day; std::cin >> cutHeight; dayDifference = day - previousDay; // std::cerr << "\n"; // std::cerr << "\n"; // std::cerr << "\n"; // std::cerr << "Dzien :" << day << "\n"; mownWeight = 0; for (Number i = 0U; i < spieciesCount; ++i) { // std::cerr << "old w :" << lawnHeight[i] << "\n"; lawnHeight[i] += dayDifference * spieces[i]; // std::cerr << "new w :" << actualHeight << "\n"; // std::cerr << "cut to:" << cutHeight << "\n"; if (lawnHeight[i] > cutHeight) { mownWeight += lawnHeight[i] - cutHeight; lawnHeight[i] = cutHeight; // std::cerr << "cutted:" << actualHeight << "\n"; } // std::cerr << "after :" << lawnHeight[i] << "\n"; } previousDay = day; mown = mownWeight; } std::string out; for (auto & mown : mowns) { out += std::to_string(mown) + "\n"; } std::cout << out; }
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 | #include <iostream> #include <limits> #include <vector> #include <array> using Number = unsigned long; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); Number spieciesCount{0}; std::cin >> spieciesCount; Number mowingCount{0}; std::cin >> mowingCount; const auto N = 500000; Number spieces[N]; Number lawnHeight[N]; //std::array<Number, N> spieces; //std::array<Number, N> lawnHeight; // std::vector<Number> spieces(spieciesCount, 0); // std::vector<Number> lawnHeight(spieciesCount, 0); std::vector<Number> mowns(mowingCount, 0); for (Number i = 0U; i < spieciesCount; ++i) { std::cin >> spieces[i]; lawnHeight[i] = 0; } Number previousDay{0}; Number day{0}; Number cutHeight{0}; Number dayDifference{0}; Number mownWeight{0}; for (auto & mown : mowns) { std::cin >> day; std::cin >> cutHeight; dayDifference = day - previousDay; // std::cerr << "\n"; // std::cerr << "\n"; // std::cerr << "\n"; // std::cerr << "Dzien :" << day << "\n"; mownWeight = 0; for (Number i = 0U; i < spieciesCount; ++i) { // std::cerr << "old w :" << lawnHeight[i] << "\n"; lawnHeight[i] += dayDifference * spieces[i]; // std::cerr << "new w :" << actualHeight << "\n"; // std::cerr << "cut to:" << cutHeight << "\n"; if (lawnHeight[i] > cutHeight) { mownWeight += lawnHeight[i] - cutHeight; lawnHeight[i] = cutHeight; // std::cerr << "cutted:" << actualHeight << "\n"; } // std::cerr << "after :" << lawnHeight[i] << "\n"; } previousDay = day; mown = mownWeight; } std::string out; for (auto & mown : mowns) { out += std::to_string(mown) + "\n"; } std::cout << out; } |