Codeforces #40 (div2) B "Martian Dollar"

問題:http://codeforces.com/contest/41/problem/B

ラクティス.

一日ずつ価値が変化する人形があり,それが売られている日数と最初の所持金,一日ずつの価値が与えられる.売買を繰り返すことで最終的に得られる最大の所持金を求める.

import java.util.*;

public class B_MartianDollar {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		long b = s.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; ++i) {
			a[i] = s.nextInt();
		}
		long result = b;
		for (int i = 0; i < n; ++i) {
			for (int j = i + 1; j < n; ++j) {
				result = Math.max(result, a[j] * (b / a[i]) + b % a[i]);
			}
		}
		System.out.println(result);
	}
}