File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments