# Untitled

unknown
plain_text
a year ago
1.5 kB
2
Indexable
Never
```#include <bits/stdc++.h>
using namespace std;
int cmp(tuple<int, int, int, int> a, tuple<int, int, int, int> b)
{
if (get<0>(a) != get<0>(b))
return get<0>(a) > get<0>(b);
else if (get<1>(a) != get<1>(b))
return get<1>(a) > get<1>(b);
else if (get<2>(a) != get<1>(b))
return get<2>(a) > get<2>(b);
else
return get<3>(a) < get<3>(b);
}
int main()
{
int T = 0;
cin >> T;
while (T--)
{
tuple<int, int, int, int> group[2005];
vector<int> Group[2005];
int N = 0;
int num = 0;
int banana = 0;
cin >> N;
for (int i = 0; i < N; i++)
{
cin >> num;
get<2>(group[i]) = num;
get<3>(group[i]) = i;
for (int j = 0; j < num; j++)
{
cin >> banana;
Group[i].emplace_back(banana);
get<0>(group[i]) += banana;
if (get<1>(group[i]) < banana)
get<1>(group[i]) = banana;
}
}
sort(group, group + N, cmp);
for (int i = 0; i < N; i++)
{
vector<int> vec = Group[get<3>(group[i])];
for (vector<int>::iterator It = vec.begin(); It != vec.end(); ++It)
{
if (It == vec.begin())
cout << *It;
else
cout << " " << *It;
}
cout << endl;
}
}
}```