#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
struct Node
{
ll time, cost;
Node(ll time = 0LL, ll cost = 0LL) : time(time), cost(cost) {}
};
Node nodes[100007];
int N;
ll ans = 0LL, cost = 0LL;
bool compare(const Node &a, const Node &b)
{
return a.cost * b.time > b.cost * a.time;
}
void input()
{
scanf("%d", &N);
for (int i = 1; i <= N; i++)
{
scanf("%lld%lld", &nodes[i].time, &nodes[i].cost);
cost += nodes[i].cost;
}
sort(nodes + 1, nodes + N + 1, compare);
}
void solve()
{
for (int i = 1; i <= N; i++)
{
cost -= nodes[i].cost;
ans += (cost * nodes[i].time);
ans += (cost * nodes[i].time);
}
}
int main()
{
input();
solve();
printf("%lld\n", ans);
return 0;
}
POJ 3262 Protecting the Flowers 贪心算法
最新推荐文章于 2024-08-04 20:54:31 发布