/* -*- coding: utf-8 -*- * * 2386.cc: No.2386 Udon Coupon (Easy) - yukicoder */ #include #include using namespace std; /* constant */ const int M = 150; /* typedef */ /* global variables */ int dp[M + 1]; /* subroutines */ inline void setmax(int &a, int b) { if (a < b) a = b; } /* main */ int main() { int n, a, b, c; scanf("%d%d%d%d", &n, &a, &b, &c); fill(dp, dp + M + 1, -1); dp[0] = 0; for (int i = 0; i + 3 <= M; i++) if (dp[i] >= 0) setmax(dp[i + 3], dp[i] + a); for (int i = 0; i + 5 <= M; i++) if (dp[i] >= 0) setmax(dp[i + 5], dp[i] + b); for (int i = 0; i + 10 <= M; i++) if (dp[i] >= 0) setmax(dp[i + 10], dp[i] + c); int s30 = max(max(10 * a, 6 * b), 3 * c); int q = n / 30, r = n % 30; int maxx = 0, maxi = min(M, n); for (int i = r; i <= maxi; i += 30) { int x = (n - i) / 30 * s30 + *max_element(dp, dp + i + 1); maxx = max(maxx, x); } printf("%d\n", maxx); return 0; }