题解 | #游游的水果大礼包#
游游的水果大礼包
http://www.nowcoder.com/questionTerminal/3013527b237a48ffbd5640345b616748
//枚举每个礼包可能出现的情况,求最大值 import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); long n = in.nextInt(),m = in.nextInt(); long a = in.nextInt(),b = in.nextInt(); long res = Integer.MIN_VALUE;//计算结果 for(int x = 0;x <= Math.min(n / 2,m);x++){ long y = Math.min(n - 2 * x,(m - x) / 2); res = Math.max(res,a * x + b * y); } System.out.println(res); } }