#include <cstdint> #include <iostream> #include <list> #include <vector> struct Meadow { int64_t a; int64_t b; bool operator<(const Meadow& other) const { return a > other.a; } }; int main() { std::ios_base::sync_with_stdio(false); int n; std::cin >> n; std::list<Meadow> meadows(n); std::vector<int64_t> result(n); for (auto&& meadow : meadows) { std::cin >> meadow.a >> meadow.b; } meadows.sort(); for (int i = 0; i < n; i++) { std::list<Meadow>::iterator minimum; int64_t minimumValue = INT64_MAX; int j = n - i; int64_t sum = 0, sumA = 0; for (auto it = meadows.begin(), last = meadows.end(); it != last; ++it) { int64_t value = it->b + it->a * --j; sum += value; value += sumA; sumA += it->a; if (value < minimumValue) { minimumValue = value; minimum = it; } } result[i] = sum; meadows.erase(minimum); } for (auto it = result.rbegin(), last = result.rend(); it != last; ++it) { std::cout << *it << '\n'; } 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 | #include <cstdint> #include <iostream> #include <list> #include <vector> struct Meadow { int64_t a; int64_t b; bool operator<(const Meadow& other) const { return a > other.a; } }; int main() { std::ios_base::sync_with_stdio(false); int n; std::cin >> n; std::list<Meadow> meadows(n); std::vector<int64_t> result(n); for (auto&& meadow : meadows) { std::cin >> meadow.a >> meadow.b; } meadows.sort(); for (int i = 0; i < n; i++) { std::list<Meadow>::iterator minimum; int64_t minimumValue = INT64_MAX; int j = n - i; int64_t sum = 0, sumA = 0; for (auto it = meadows.begin(), last = meadows.end(); it != last; ++it) { int64_t value = it->b + it->a * --j; sum += value; value += sumA; sumA += it->a; if (value < minimumValue) { minimumValue = value; minimum = it; } } result[i] = sum; meadows.erase(minimum); } for (auto it = result.rbegin(), last = result.rend(); it != last; ++it) { std::cout << *it << '\n'; } return 0; } |