-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.cpp
More file actions
45 lines (40 loc) · 951 Bytes
/
Copy path2.cpp
File metadata and controls
45 lines (40 loc) · 951 Bytes
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
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using ii = pair<ll, ll>;
using vii = vector<ii>;
void tc() {
ll n, m;
cin >> n >> m;
vector<vll> ve(n, vll(m)); // 原数组
for (vll &ve2 : ve) {
for (ll &i : ve2) cin >> i;
}
vll vsum(n, 0); // 这一列的和
for (ll i = 0; i < n; i++) {
for (ll j : ve[i]) vsum[i] += j;
}
vll th(n); // 第几大
iota(th.begin(), th.end(), 0);
sort(th.begin(), th.end(), [&](ll a, ll b) { return vsum[a] > vsum[b]; });
ll ans = 0;
for (ll i = 0; i < n; i++) {
ans += vsum[th[i]] * (n - 1 - i) * m;
}
for (vll ve2 : ve) {
for (ll i = 0; i < m; i++) {
ans += ve2[i] * (m - i);
}
}
cout << ans << '\n';
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
ll T;
cin >> T;
while (T--) {
tc();
}
return 0;
}