#include<vector>
#include<iostream>
#include<iomanip>
#include<set>
#include<string>
#include<map>
#include<algorithm>
#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<stack>
#include<ctype.h>
#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb push_back
#define mp make_pair
#define fia(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define fib(i,a,b) for(int i=(int)(b);i>(int)(a);i--)
using namespace std;
typedef struct work{
int extra;
int normalt;
long long deadline;
}work;
int comp(const void * a, const void * b)
{
work *ma =(work *)a;
work *mb = (work *)b;
long long dd1,dd2;
dd1 = ma->deadline;
dd2 = mb->deadline;
int com1,com2,co1,co2;
com1= ma->normalt;
com2= mb->normalt;
co1= ma->extra;
co2= mb->extra;
if(dd1-dd2>0)
return -1;
if(dd1==dd2)
{
if((double)((com1-dd1)/(co1))<(double)((com2-dd2)/(co2)))
return -1;
else if((double)((com1-dd1)/(co1))>(double)((com2-dd2)/(co2)))
return 1;
else
return 0;
}
return 1;
}
work works[100000];
int main()
{
int t,n;
scanf("%d",&t);
int a,b;
while(t--)
{
scanf("%d",&n);
rep(i,n)
{
scanf("%d %d %lld",&works[i].extra,&works[i].normalt,&works[i].deadline);
}
qsort(works, n, sizeof(works[0]), comp);
long double sum=0;
rep(i,n)
{
long double temp=(long double)((works[i].normalt-works[i].deadline)/works[i].extra);
if(temp>(long double)(0.0))sum+=temp;
}
cout<<fixed<<setprecision(2)<<sum<<endl;
}
system("pause");
return 0;
}
i don't know what is going wrong in this program whether there any accuracy issue or something is wrong with my algorithm
plzz help thnks in advance
