Skip to content

Commit 048cd61

Browse files
authored
Merge pull request #867 from AlgorithmWithGod/lkhyun
[20250911] BOJ / G4 / 고층 건물 / 이강현
2 parents bcf59bc + 2dea92d commit 048cd61

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
static StringTokenizer st;
9+
static int N;
10+
static int[] buildings;
11+
static int[] cnt;
12+
static int max;
13+
14+
public static void main(String[] args) throws IOException {
15+
N = Integer.parseInt(br.readLine());
16+
buildings = new int[N+1];
17+
cnt = new int[N+1];
18+
19+
st = new StringTokenizer(br.readLine());
20+
for (int i = 1; i <= N; i++) {
21+
buildings[i] = Integer.parseInt(st.nextToken());
22+
}
23+
24+
for (int i = 1; i < N; i++) {
25+
for (int j = i+1; j <= N; j++) {
26+
double slope = (double)(buildings[j]-buildings[i]) / (j-i);
27+
boolean isPossible = true;
28+
for (int k = 1; i+k < j; k++) {
29+
if(buildings[i]+(slope*k) <= buildings[i+k]){
30+
isPossible = false;
31+
break;
32+
}
33+
}
34+
if(isPossible){
35+
cnt[i]++;
36+
cnt[j]++;
37+
}
38+
}
39+
}
40+
for (int i = 1; i <= N; i++) {
41+
max = Math.max(cnt[i], max);
42+
}
43+
bw.write(max+"");
44+
bw.close();
45+
}
46+
}
47+
```

0 commit comments

Comments
 (0)