题解 | #[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;
}
全部评论

相关推荐

头像
02-15 16:23
中南大学 Java
野猪不是猪🐗:签了美团真是不一样! 亲戚们都知道我签了美团,过年都围着我问送一单多少钱,还让弟弟妹妹们引以为戒,笑我爸我妈养了个🐢孩子,说从小就知道我这个人以后肯定没出息,我被骂的都快上天了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务