I

来源poj2970

A new web-design studio, called SMART (Simply Masters of ART), employs two people. The first one is a web-designer and an executive director at the same time. The second one is a programmer. The director is so a nimble guy that the studio has already got N contracts for web site development. Each contract has a deadline di.

It is known that the programmer is lazy. Usually he does not work as fast as he could. Therefore, under normal conditions the programmer needs bi of time to perform the contract number i. Fortunately, the guy is very greedy for money. If the director pays him xi dollars extra, he needs only (bi − ai xi) of time to do his job. But this extra payment does not influent other contract. It means that each contract should be paid separately to be done faster. The programmer is so greedy that he can do his job almost instantly if the extra payment is (bi ⁄ ai) dollars for the contract number i.

The director has a difficult problem to solve. He needs to organize programmer’s job and, may be, assign extra payments for some of the contracts so that all contracts are performed in time. Obviously he wishes to minimize the sum of extra payments. Help the director!

Input

The first line of the input contains the number of contracts N (1 ≤ N ≤ 100 000, integer). Each of the next N lines describes one contract and contains integer numbers ai, bi, di (1 ≤ ai, bi ≤ 10 000; 1 ≤ di ≤ 1 000 000 000) separated by spaces.

Output

The output needs to contain a single real number S in the only line of file. S is the minimum sum of money which the director needs to pay extra so that the programmer could perform all contracts in time. The number must have two digits after the decimal point.

Sample Input

2
20 50 100
10 100 50

Sample Output

5.00

按deadline排序,然后时间不够的,先之前的买,poj输出有问题%.2lf过不了%.2f才行

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h> 
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define scf(x) scanf("%d",&x)
#define scff(x,y) scanf("%d%d",&x,&y)
#define prf(x) printf("%d
",x) 
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+7;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
using namespace std;
const double pi=acos(-1.0);
const int N=1e5+10;
struct test
{
	int a,time,dead;
	friend bool operator <(test a,test b)
	{
		return a.a<b.a;
	}
}a[N];
bool cmp(test a,test b)
{
	return a.dead<b.dead;
}
priority_queue<test>v;
int main()
{
	int n;scf(n);
	rep(i,0,n)
	sf("%d%d%d",&a[i].a,&a[i].time,&a[i].dead);
	sort(a,a+n,cmp);
	test t;
	int now=0;
	double money=0.0;
	rep(i,0,n)
	{
		v.push(a[i]);
		if(a[i].time+now>a[i].dead)
		{
			int chaju=a[i].time+now-a[i].dead;
			now=a[i].dead;
			while(chaju>0)
			{
				t=v.top();
				v.pop();
				if(t.time>chaju)
				{
					money+=1.0*chaju/t.a;
					t.time-=chaju;
					chaju=0;
					v.push(t); 
				}else
				{
					money+=1.0*t.time/t.a;
					chaju-=t.time;
				}
			}
		}else
		now+=a[i].time;
	}
	pf("%.2f
",money);
	return 0;
}
原文地址:https://www.cnblogs.com/wzl19981116/p/9502581.html