-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2largerarray.cpp
More file actions
37 lines (27 loc) · 843 Bytes
/
Copy path2largerarray.cpp
File metadata and controls
37 lines (27 loc) · 843 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
#include <stdio.h>
int main() {
int T; // Number of subarrays
int N; // Number of elements in each subarray
scanf("%d", &T);
scanf("%d", &N);
int subarrays[T][N]; // Create a 2D array to store all the subarrays
int sum[T]; // Create an array to store the sum of each subarray
// Input the subarrays
for (int i = 0; i < T; i++) {
int subarray_total = 0; // Initialize a variable to store the total of the current subarray
for (int j = 0; j < N; j++) {
scanf("%d", &subarrays[i][j]);
subarray_total += subarrays[i][j];
}
sum[i] = subarray_total;
}
int max = 0;
// Calculate the maximum total
for (int i = 0; i < T; i++) {
if (sum[i] > max) {
max = sum[i];
}
}
printf("%d", max);
return 0;
}