题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1634
解:大力贪心。。。
每次取d/t最大的那个。
程序:
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; struct ding{ int t,d; double y; }x[200000]; int n; bool cmp(const ding&a,const ding&b){return (a.y>b.y);} int main() { scanf("%d",&n); for (int i=1;i<=n;i++) { scanf("%d%d",&x[i].t,&x[i].d); x[i].y=(double)x[i].d/x[i].t; } sort(x+1,x+1+n,cmp); long long ans=0,tim=0; for (int i=1;i<=n;i++) { ans+=tim*x[i].d; tim+=x[i].t+x[i].t; } printf("%lld\n",ans); return 0; }