题解 | #[USACO 2007 Jan S]Protecting the Flowers#
[USACO 2007 Jan S]Protecting the Flowers
https://ac.nowcoder.com/acm/problem/25043
感觉用不着前缀和
#include <algorithm>
using namespace std;
int n;
struct ty
{
int ti;
int fdead;
}myty[100010];
long long result,count1;
bool compare(ty a,ty b)
{
return (a.ti*1.0/a.fdead)<(b.ti*1.0/b.fdead);
}
int main(void)
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>myty[i].ti>>myty[i].fdead;
}
sort(myty+1,myty+1+n,compare);
for(int i=2;i<=n;i++)
{
count1+=2*(myty[i-1].ti);
result+=count1*myty[i].fdead;
}
cout<<result;
return 0;
}