第一道
public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] v = new int[n];
		for(int i = 0 ; i < n ; i++){
			v[i] = in.nextInt();
		}
		int[][] dp = new int[n][n];
		for(int i = 0 ; i < n ; i++){
			dp[i][i] = v[i]*n;
		}
		for(int j = 1 ; j < n ; j++){
			for(int i = j-1 ; i >= 0 ; i--){
				dp[i][j] = Math.max(dp[i+1][j] + v[i]*(n-j+i), dp[i][j-1]+v[j]*(n-j+i));
			}
		}
		System.out.println(dp[0][n-1]);
	}
第二道
public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int V = in.nextInt();
		int[] m = new int[n];
		int[] w = new int[n];
		int[] s = new int[n];
		for(int i = 0 ; i < n ; i++){
			m[i] = in.nextInt();
			w[i] = in.nextInt();
			s[i] = in.nextInt();
		}
		int[][] dp = new int[n+1][V+1];
		for(int i = 1 ; i <= n ; i++){
			for(int j = w[i-1] ; j <= V ; j++){
				dp[i][j] = dp[i-1][j];
				for(int k = 1 ; k <= m[i-1] ; k++){
					if(j < k*w[i-1]){
						break;
					}
					dp[i][j] = Math.max(dp[i][j], dp[i-1][j-k*w[i-1]]+k*s[i-1]);
				}
			}
		}
		System.out.println(dp[n][V]);
	}