-
Notifications
You must be signed in to change notification settings - Fork 457
/
Copy pathSolution.c
41 lines (39 loc) Β· 996 Bytes
/
Solution.c
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
#include <assert.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
int arr[6][6];
for(int i=0;i<6;i++){
for(int j=0;j<6;j++){
scanf("%d", &arr[i][j]);
}
}
int max_sum = 0;
int temp_sum;
for(int i = 0; i < 4; i++) {
for(int j = 0; j < 4; j++) {
temp_sum = 0;
// top row
temp_sum += arr[i][j];
temp_sum += arr[i][j+1];
temp_sum += arr[i][j+2];
//middle
temp_sum += arr[i+1][j+1];
//bottom row
temp_sum += arr[i+2][j];
temp_sum += arr[i+2][j+1];
temp_sum += arr[i+2][j+2];
//if first hourglass, set as max
if(temp_sum > max_sum || i == 0 && j == 0)
max_sum = temp_sum;
}
}
printf("%d\n", max_sum);
return 0;
}