-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmonk-and-operartions.cpp
59 lines (48 loc) · 1.12 KB
/
monk-and-operartions.cpp
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
58
59
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
const int N = 2e5 + 11;
void solve() {
int n, m;
cin >> n >> m;
int v1, v2, v3, v4;
int mat[n][m];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> mat[i][j];
cin >> v1 >> v2 >> v3 >> v4;
ll total_sum_a = INT32_MIN;
ll total_sum_b = INT32_MIN;
ll grand_total_a = 0;
ll grand_total_b = 0;
ll sum = 0;
ll added_sum = 0;
for (int i = 0; i < n; i++) {
sum = 0;
added_sum = 0;
total_sum_a = INT32_MIN;
for (int j = 0; j < m; j++)
sum += abs(mat[i][j]);
for (int j = 0; j < m; j++)
added_sum += abs(mat[i][j] + v1);
total_sum_a = max(total_sum_a, sum);
total_sum_a = max(total_sum_a, added_sum);
total_sum_a = max(total_sum_a, 1LL * n * v2);
grand_total_a += total_sum_a;
}
cout << max(grand_total_a, grand_total_b) << endl;
}
int main() {
freopen("input.txt", "r", stdin);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int no_of_test_cases = 1;
cin >> no_of_test_cases;
while (no_of_test_cases--)solve();
return 0;
}