#include #include #include #include using namespace std; typedef long long LL; struct Order{ int S; int X; int D; int P; }; struct UnweightedOrder{ int S; int X; int D; }; bool PenaltyOrder(const Order& a, const Order& b){ return a.P>b.P; } bool StartOrder(const UnweightedOrder& a,const UnweightedOrder&b){ return a.S>b.S; } int T; int N; Order order[210]; LL Calc(vector uo){ int i; sort(uo.begin(),uo.end(),StartOrder); set s; for(i=0;i v(s.begin(),s.end()); int last = 0; vector seg; for(int i=1;i=0&&cur;--j){ if(uo[i].S<=v[j]&&uo[i].D>v[j]){ if(seg[j]<=cur){ cur-=seg[j]; seg[j] = 0; } else{ seg[j] -= cur; cur = 0; } } } ret+=cur; } return ret; } int main(){ int i,j; cin>>T; while(T--){ cin>>N; for(i=0;i>order[i].S>>order[i].X>>order[i].D>>order[i].P; } sort(order,order+N,PenaltyOrder); LL res = 0; vector no; UnweightedOrder first = {order[0].S,order[0].X,order[0].D}; no.push_back(first); for(i=1;i to = no; to.push_back(current); LL temp = Calc(to); current.X-=temp; res = res + temp*order[i].P; no.push_back(current); } cout<