Skip to content

Commit acda8a0

Browse files
authored
Merge pull request #881 from AlgorithmWithGod/JHLEE325
[20250913] BOJ / G4 / 팀 빌딩 / 이준희
2 parents ee5cdfd + a872680 commit acda8a0

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
7+
public static void main(String[] args) throws IOException {
8+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
9+
StringTokenizer st;
10+
11+
int n = Integer.parseInt(br.readLine());
12+
13+
int[] pgm = new int[n];
14+
15+
st = new StringTokenizer(br.readLine());
16+
17+
for (int i = 0; i < n; i++) {
18+
pgm[i] = Integer.parseInt(st.nextToken());
19+
}
20+
21+
int left = 0;
22+
int right = n - 1;
23+
int res = 0;
24+
25+
while (left < right) {
26+
res = Math.max((right - left - 1) * Math.min(pgm[left], pgm[right]), res);
27+
if (pgm[left] <= pgm[right]) {
28+
left++;
29+
} else {
30+
right--;
31+
}
32+
}
33+
34+
System.out.println(res);
35+
}
36+
}
37+
```

0 commit comments

Comments
 (0)