当前位置: 代码迷 >> 综合 >> 牛客—— [USACO 2007 Jan S] Protecting the Flowers(贪心)
  详细解决方案

牛客—— [USACO 2007 Jan S] Protecting the Flowers(贪心)

热度:56   发布时间:2023-11-22 05:08:24.0

[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);
}
  相关解决方案