fork download
  1. #pragma GCC optimize("O3")
  2. #define TASK ""
  3. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
  4. #define __USE_MINGW_ANSI_STDIO 0
  5. #include<bits/stdc++.h>
  6. using namespace std;
  7.  
  8. #define PI acos(-1)
  9. #define pb push_back
  10. #define fi first
  11. #define se second
  12. #define sz(a) (int)(a).size()
  13. #define all(c) (c).begin(), (c).end()
  14. #define TIMESTAMP fprintf(stderr, "Execution time: %.3lf s.\n", (double)clock()/CLOCKS_PER_SEC)
  15.  
  16. typedef long long ll;
  17. typedef long double ld;
  18. typedef vector<int> vi;
  19. typedef vector<ll> vll;
  20. typedef pair <int, int> pii;
  21. typedef vector <vi> vvi;
  22. typedef vector <pii> vpii;
  23. typedef vector<string> vs;
  24.  
  25. const int MAXN = 1e5 + 9;
  26. const int MOD = (int)(1e9 + 7);
  27. const int INF = 10000000;
  28.  
  29. struct level {
  30. ll a, b, p;
  31. };
  32.  
  33. int n;
  34. level aa[MAXN];
  35. ll prsum[MAXN];
  36. ll sfsum[MAXN];
  37.  
  38. bool cmp(level l1, level l2) {
  39. 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;
  40. 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;
  41. return (l1.a - l1.b < l2.a - l2.b);
  42. }
  43.  
  44. void input() {
  45. cin >> n;
  46. for(int i = 0; i < n; i++) {
  47. cin >> aa[i].a >> aa[i].b >> aa[i].p;
  48. }
  49. }
  50.  
  51. void solve() {
  52. sort(aa, aa + n, cmp);
  53. prsum[0] = aa[0].a;
  54. for(int i = 1; i < n; i++) prsum[i] = prsum[i - 1] + aa[i].a;
  55. sfsum[n] = 0;
  56. sfsum[n - 1] = aa[n - 1].b;
  57. for(int i = n - 2; i >= 0; i--) sfsum[i] = sfsum[i + 1] + aa[i].b;
  58. ld ans = 0;
  59. for(int i = 0; i < n; i++) {
  60. ans += (ld(prsum[i]) + ld(sfsum[i + 1])) * (ld(aa[i].p)) / (ld(1e7));
  61. }
  62. cout << fixed << setprecision(10) << ans << endl;
  63. }
  64.  
  65. int main() {
  66. ios_base::sync_with_stdio(0);
  67. cin.tie(0);
  68. #ifdef LOCAL
  69. freopen("xxx.in", "r", stdin);
  70. freopen("xxx.out", "w", stdout);
  71. #else
  72. //freopen(TASK".in", "r", stdin);
  73. //freopen(TASKa".out", "w", stdout);
  74. #endif
  75. int tt;
  76. cin >> tt;
  77. while(tt--) {
  78. input();
  79. solve();
  80. }
  81. return 0;
  82. }
Success #stdin #stdout 0s 19152KB
stdin
Standard input is empty
stdout
Standard output is empty