暴力解:
提交的代码
提交时间:2018-03-12 语言:Java 运行时间: 408 ms 占用内存:23136K 状态:答案正确
不知为何才408ms
package com.test;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(
new BufferedReader(new InputStreamReader(System.in)));
while (in.hasNext()) {
int n = in.nextInt();
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextInt();
}
int res = getRes(a);
System.out.println(res);
}
in.close();
}
private static int getRes(int[] a) {
int len = a.length;
int max = a[0];
for (int i = 0; i < len; i++) {
int minHigh = a[i];
for (int j = i + 1; j < len; j++) {
minHigh = Math.min(minHigh, a[j]);
max = Math.max((j-i+1) * minHigh, max);
}
}
return max;
}
}