#include #include #define NUM_OF(arr) (sizeof(arr)/sizeof(*arr)) using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); const int cost[] = { 3, 5, 10 }; int N, discount[NUM_OF(cost)], i, j; cin >> N; for (i = 0; i != NUM_OF(cost); ++i) cin >> discount[i]; vector dp(N + 1, 0); dp[0] = 0; for (i = 0; i != N; ++i) { for (j = 0; j != NUM_OF(cost) && i + cost[j] <= N; ++j) if (dp[i] + discount[j] > dp[i + cost[j]]) dp[i + cost[j]] = dp[i] + discount[j]; if (dp[i] > dp[i + 1]) dp[i + 1] = dp[i]; } cout << dp[N] << '\n'; return 0; }