fork download
#pragma GCC optimize("O3") 
#define TASK ""
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") 
#define __USE_MINGW_ANSI_STDIO 0
#include<bits/stdc++.h>                               
using namespace std;

#define PI acos(-1)
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(c) (c).begin(), (c).end()
#define TIMESTAMP fprintf(stderr, "Execution time: %.3lf s.\n", (double)clock()/CLOCKS_PER_SEC)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair <int, int> pii;
typedef vector <vi> vvi;
typedef vector <pii> vpii;
typedef vector<string> vs;

const int MAXN = 1e5 + 9;
const int MOD = (int)(1e9 + 7);
const int INF = 10000000;

struct level {
	ll a, b, p;
};

int n;
level aa[MAXN];
ll prsum[MAXN];
ll sfsum[MAXN];

bool cmp(level l1, level l2) {
	if((l1.a + l2.b) * l1.p + (l2.a + l1.a) * l2.p < (l2.a + l1.b) * l2.p + (l2.a + l1.a) * l1.p) return 1;
	if((l1.a + l2.b) * l1.p + (l2.a + l1.a) * l2.p > (l2.a + l1.b) * l2.p + (l2.a + l1.a) * l1.p) return 0;
	return (l1.a - l1.b < l2.a - l2.b);
}

void input() {
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> aa[i].a >> aa[i].b >> aa[i].p;
	}
}

void solve() {
	sort(aa, aa + n, cmp);
	prsum[0] = aa[0].a;
	for(int i = 1; i < n; i++) prsum[i] = prsum[i - 1] + aa[i].a;
	sfsum[n] = 0;
	sfsum[n - 1] = aa[n - 1].b;
	for(int i = n - 2; i >= 0; i--) sfsum[i] = sfsum[i + 1] + aa[i].b;
	ld ans = 0;
	for(int i = 0; i < n; i++) {
		ans += (ld(prsum[i]) + ld(sfsum[i + 1])) * (ld(aa[i].p)) / (ld(1e7));
	}
	cout << fixed << setprecision(10) << ans << endl;	
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifdef LOCAL
	freopen("xxx.in", "r", stdin);
	freopen("xxx.out", "w", stdout);
#else
	//freopen(TASK".in", "r", stdin);
	//freopen(TASKa".out", "w", stdout);
#endif	
	int tt;
	cin >> tt;
	while(tt--) {
		input();
		solve();
	}
	return 0;
}
Success #stdin #stdout 0s 19152KB
stdin
Standard input is empty
stdout
Standard output is empty