byte1.java 1.1 KB
Newer Older
L
liu13 已提交
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
package interview;

import java.util.Scanner;

public class byte1 {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }

        int res = Integer.MIN_VALUE;
        int[] dp = new int[n];
        dp[0] = arr[0];
        for (int i = 1; i < n; i++) {
            dp[i] = Math.max(dp[i-1], arr[i]+i);
        }
        for (int i = 1; i < n ; i++) {
            res = Math.max(arr[i]-i+dp[i-1], res);
        }
        System.out.println(res);
    }

    public static void main2 (String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        int res = 0;
        for (int i = 0; i < n ; i++) {
            for (int j = 0; j < i ; j++) {
                int temp = arr[i]+arr[j]-i+j;
                res = Math.max(res, temp);
            }
        }
        System.out.println(res);
    }
}