CRED Coins codechef solution in c++

#include<bits/stdc++.h>
using namespace std;

#define int long long

int solve(vector<int>& coins, int target) {
    int n = coins.size();
    vector<int> dp(target + 1, LLONG_MAX);
    dp[0] = 0;

    for (int i = 1; i <= target; ++i) {
        for (int j = 0; j < n; ++j) {
            if (coins[j] <= i && dp[i - coins[j]] != LLONG_MAX) {
                dp[i] = min(dp[i], 1 + dp[i - coins[j]]);
            }
        }
    }

    return (dp[target] == LLONG_MAX) ? -1 : dp[target];
}

int32_t main() {
    int n, target;
    cin >> n >> target;
    vector<int> coins(n);

    for (int i = 0; i < n; ++i) {
        cin >> coins[i];
    }

    int result = solve(coins, target);
    cout << result << endl;

    return 0;
}

This C++ code defines a solution for the "CRED Coins" problem on CodeChef. The solve function uses dynamic programming to find the minimum number of coins required to achieve the target value. The main function reads the input values, calls the solve function, and prints the result.