-
Notifications
You must be signed in to change notification settings - Fork 2
/
Erupting_Volcanoes.cpp
53 lines (50 loc) · 2.08 KB
/
Erupting_Volcanoes.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
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int m;
cin >> m;
vector<int> volcano[m];
int score[n][n];
memset(score, 0, sizeof score);
int maxScore = 0;
for(int a0 = 0; a0 < m; a0++){
int x;
int y;
int w;
cin >> x >> y >> w;
volcano[a0].push_back(x);
volcano[a0].push_back(y);
volcano[a0].push_back(w);
if(maxScore < w) maxScore = w;
score[x][y] += w;
}
for(int i = 0; i < m; ++i){
int power = volcano[i][2];
while(power-- > 1){
for(int l = -power; l <= power; ++l){
if(volcano[i][1] + l >= 0 && volcano[i][1] + l < n && volcano[i][0] - power >= 0 && volcano[i][0] - power < n){
score[volcano[i][0] - power][volcano[i][1] + l] += volcano[i][2] - power;
maxScore = max(score[volcano[i][0] - power][volcano[i][1] + l], maxScore);
}
if(volcano[i][1] + l >= 0 && volcano[i][1] + l < n && volcano[i][0] + power >= 0 && volcano[i][0] + power < n){
score[volcano[i][0] + power][volcano[i][1] + l] += volcano[i][2] - power;
maxScore = max(score[volcano[i][0] + power][volcano[i][1] + l], maxScore);
}
}
for(int k = -power+1; k <= power-1; ++k){
if(volcano[i][0] + k >= 0 && volcano[i][0] + k < n && volcano[i][1] - power >= 0 && volcano[i][1] - power < n){
score[volcano[i][0] + k][volcano[i][1] - power] += volcano[i][2] - power;
maxScore = max(score[volcano[i][0] + k][volcano[i][1] - power], maxScore);
}
if(volcano[i][0] + k >= 0 && volcano[i][0] + k < n && volcano[i][1] + power >= 0 && volcano[i][1] + power < n){
score[volcano[i][0] + k][volcano[i][1] + power] += volcano[i][2] - power;
maxScore = max(score[volcano[i][0] + k][volcano[i][1] + power], maxScore);
}
}
}
}
cout<<maxScore<<endl;
return 0;
}