fork download
  1. #include<bits/stdc++.h>
  2.  
  3. typedef long long LL;
  4. using namespace std;
  5.  
  6. #define fillchar(a, x) memset(a, x, sizeof(a))
  7. #define MP make_pair
  8. #define PB push_back
  9. #define endl '\n'
  10.  
  11. const LL M = (LL)1e9+7;
  12.  
  13. struct pt
  14. {
  15. LL x;
  16. int a;
  17. int b;
  18. };
  19.  
  20. bool operator <(const pt &a,const pt &b)
  21. {
  22. if(a.a == a.b) return true;
  23. if(b.a == b.b) return false;
  24.  
  25. LL d1 = a.x*(b.a-b.b);
  26. LL d2 = b.x*(a.a-a.b);
  27.  
  28. return d2<d1;
  29. }
  30.  
  31. int main()
  32. {
  33. ios_base::sync_with_stdio(0);
  34. cout.precision(15);
  35. cout.setf(ios::fixed);
  36.  
  37. int t;
  38.  
  39. cin >> t;
  40.  
  41. while(t--)
  42. {
  43. int n;
  44. cin >> n;
  45. vector <pt> v(n);
  46.  
  47. for(LL i=0;i<n;i++)
  48. {
  49. cin >> v[i].a>>v[i].b>>v[i].x;
  50. // v[i].p /= 1e7;
  51. }
  52.  
  53. sort(v.begin(),v.end());
  54.  
  55. LL ans = 0;
  56. LL c1 = 0, c2 = (LL)1e7;
  57.  
  58. for(LL i=0;i<n;i++)
  59. {
  60. ans += c1*v[i].b + c2*v[i].a;
  61.  
  62. c1 += v[i].x;
  63. c2 -= v[i].x;
  64. }
  65.  
  66. double ans2 = ans/1e7;
  67.  
  68. cout<<ans2<<endl;
  69. }
  70.  
  71. }
  72.  
Runtime error #stdin #stdout 0s 15416KB
stdin
Standard input is empty
stdout
Standard output is empty