#include <iostream> #include <cstdint> #include <limits> #include <map> #include <vector> struct Data { Data() : height(0), count(1) {} uint64_t height; uint64_t count; }; int main() { std::ios_base::sync_with_stdio(0); // uint32_t N = 0, M = 0; std::cin >> N >> M; std::map<uint64_t, Data, std::greater<uint64_t>> map; std::vector<uint64_t> cuts(M); for (uint32_t i = 0; i < N; ++i) { uint64_t temp = 0; std::cin >> temp; auto iter = map.find(temp); if (iter != map.end()) { iter->second.count++; } else { map.insert(std::make_pair(temp, Data())); } } for (uint32_t i = 0; i < M; ++i) { uint64_t temp = 0; std::cin >> temp >> cuts[i]; } // for (uint32_t i = 0; i < M; ++i) { uint64_t weight = 0; for (auto &j : map) j.second.height += j.first; for (auto &j : map) { if (j.second.height <= cuts[i]) break; weight += (j.second.height - cuts[i]) * j.second.count; j.second.height = cuts[i]; } std::cout << weight << 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | #include <iostream> #include <cstdint> #include <limits> #include <map> #include <vector> struct Data { Data() : height(0), count(1) {} uint64_t height; uint64_t count; }; int main() { std::ios_base::sync_with_stdio(0); // uint32_t N = 0, M = 0; std::cin >> N >> M; std::map<uint64_t, Data, std::greater<uint64_t>> map; std::vector<uint64_t> cuts(M); for (uint32_t i = 0; i < N; ++i) { uint64_t temp = 0; std::cin >> temp; auto iter = map.find(temp); if (iter != map.end()) { iter->second.count++; } else { map.insert(std::make_pair(temp, Data())); } } for (uint32_t i = 0; i < M; ++i) { uint64_t temp = 0; std::cin >> temp >> cuts[i]; } // for (uint32_t i = 0; i < M; ++i) { uint64_t weight = 0; for (auto &j : map) j.second.height += j.first; for (auto &j : map) { if (j.second.height <= cuts[i]) break; weight += (j.second.height - cuts[i]) * j.second.count; j.second.height = cuts[i]; } std::cout << weight << std::endl; } return 0; } |