[USACO 2007 Jan S] Protecting the Flowers
题目链接:
https://ac.nowcoder.com/acm/problem/25043
#include<bits/stdc++.h>using namespace std;
typedef long long ll;
const int N = 2e6 + 10;struct cow{
int t,d;double s;
}q[N];bool cmp(cow a, cow b){
return a.s < b.s;
}int n;int main()
{
scanf("%d",&n);ll sum = 0;for(int i = 0 ; i < n ; i ++){
int t,d;scanf("%d %d",&t,&d);q[i] = {
t,d,t*1.0/d};sum += d;}sort(q,q+n,cmp);ll ans = 0;for(int i = 0 ; i < n ; i ++){
sum -= q[i].d;ans += sum *q[i].t*2;}printf("%lld",ans);
}