#include <bits/stdc++.h>
using namespace std;
struct extra{
int time_taken;
int efficiency;
};
struct compare{
bool operator()(auto x,auto y){
return x.efficiency<y.efficiency;
}
};
int main(){
ios::sync_with_stdio(0);
cin.tie(NULL);
int t;
cin>>t;
cout<<fixed;
cout<<setprecision(2);
while(t--){
int n;
cin>>n;
extra a[100000];
pair<int,int> b[100000];
for(int i=0;i<n;i++){
cin>>a[i].efficiency;
cin>>a[i].time_taken;
cin>>b[i].first;
b[i].second=i;
}
sort(b,b+n,[](auto x,auto y){
return x.first<y.first;
});
int prev_time=0,time_left=0;
double cost=0;
priority_queue<extra,vector<extra>,compare> pq;
for(int i=0;i<n;i++){
pq.push(a[b[i].second]);
time_left=b[i].first - prev_time;
int time_taken=a[b[i].second].time_taken;
if(time_taken<time_left){
prev_time+=time_taken;
}
else if(time_taken==time_left){
prev_time=b[i].first;
}
else{
int extra_time_needed=time_taken-time_left;
while(extra_time_needed>0){
auto x=pq.top();
if(x.time_taken<=extra_time_needed){
cost+=(double)x.time_taken/x.efficiency;
extra_time_needed-=x.time_taken;
pq.pop();
}
else if(x.time_taken>extra_time_needed){
pq.pop();
extra tmp;
tmp.time_taken=x.time_taken - extra_time_needed;
tmp.efficiency=x.efficiency;
pq.push(tmp);
cost+=(double)extra_time_needed/x.efficiency;
extra_time_needed=0;
}
}
prev_time=b[i].first;
}
}
cout<<cost<<'\n';
}
}
using namespace std;
struct extra{
int time_taken;
int efficiency;
};
struct compare{
bool operator()(auto x,auto y){
return x.efficiency<y.efficiency;
}
};
int main(){
ios::sync_with_stdio(0);
cin.tie(NULL);
int t;
cin>>t;
cout<<fixed;
cout<<setprecision(2);
while(t--){
int n;
cin>>n;
extra a[100000];
pair<int,int> b[100000];
for(int i=0;i<n;i++){
cin>>a[i].efficiency;
cin>>a[i].time_taken;
cin>>b[i].first;
b[i].second=i;
}
sort(b,b+n,[](auto x,auto y){
return x.first<y.first;
});
int prev_time=0,time_left=0;
double cost=0;
priority_queue<extra,vector<extra>,compare> pq;
for(int i=0;i<n;i++){
pq.push(a[b[i].second]);
time_left=b[i].first - prev_time;
int time_taken=a[b[i].second].time_taken;
if(time_taken<time_left){
prev_time+=time_taken;
}
else if(time_taken==time_left){
prev_time=b[i].first;
}
else{
int extra_time_needed=time_taken-time_left;
while(extra_time_needed>0){
auto x=pq.top();
if(x.time_taken<=extra_time_needed){
cost+=(double)x.time_taken/x.efficiency;
extra_time_needed-=x.time_taken;
pq.pop();
}
else if(x.time_taken>extra_time_needed){
pq.pop();
extra tmp;
tmp.time_taken=x.time_taken - extra_time_needed;
tmp.efficiency=x.efficiency;
pq.push(tmp);
cost+=(double)extra_time_needed/x.efficiency;
extra_time_needed=0;
}
}
prev_time=b[i].first;
}
}
cout<<cost<<'\n';
}
}
Comments
Post a Comment