-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1859B.cpp
More file actions
57 lines (52 loc) · 1.24 KB
/
1859B.cpp
File metadata and controls
57 lines (52 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<bits/stdc++.h>
using namespace std;
/* void solver(){
int n;
cin>>n;
long long sum = 0;
int min_ans = INT_MAX;
for(int i = 0 ; i < n ;i++){
int m;
cin>>m;
vector<int>arr(m);
for(int j = 0 ; j < m ;j++){
cin>>arr[j];
}
sort(arr.begin() , arr.end());
int second_min = arr[1];
int first_min= arr[0];
sum+=second_min;
min_ans = min(min_ans,first_min);
}
cout<<sum - min_ans<<endl;
}
*/
#include<bits/stdc++.h>
using namespace std;
void solver(){
int n;
cin >> n;
long long sum_second = 0;
int min_first = INT_MAX;
int min_second = INT_MAX;
for(int i = 0; i < n; i++){
int m;
cin >> m;
vector<int> arr(m);
for(int j = 0; j < m; j++){
cin >> arr[j];
}
sort(arr.begin(), arr.end());
int first_min = arr[0];
int second_min = arr[1];
sum_second += second_min;
min_first = min(min_first, first_min);
min_second = min(min_second, second_min);
}
cout << sum_second + min_first - min_second << endl;
}
int main(){
int t;
cin>>t;
while(t--){solver();}
}