1

噢莫加纳加加加  •  7天前


#include <bits/stdc++.h>
using namespace std;
int n;
struct node {
    int a, c;
};
node a[100005];
bool cmp(node x, node y) {//哪个排前面总用时最少,哪个排前面
    return (x.a + y.a) * x.c + y.a * y.c > (x.a + y.a) * y.c + x.a * x.c;
}
long long sum = 0, ans = 0;
int main() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i].a >> a[i].c;
    }
    sort(a + 1, a + n + 1, cmp);//排序
    for(int i = 1; i <= n; i++) {//模拟计算总用时
        sum += a[i].a;//总访问次数
        ans += sum * a[i].c;
    }
    cout << ans;
    return 0;
}

评论:

请先登录,才能进行评论