p248.in2
======================
2
7 4
9


=================
p248.ans1
======================
2

=================
p248.in1
======================
2
2 4
6

=================
p248.ans2
======================
-1

=================
p248.cpp
======================
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

int n;
vector<int> c;
int V;

void read() {
    cin >> n;
    c.resize(n);
    cin >> c;
    cin >> V;
}

void solve() {
    // This solution uses dynamic programming to solve a coin change variant
    // where we need to find the minimum number of variables(coins) to make
    // exactly the target value V.The array dp[v] stores the minimum sum of
    // variables needed to achieve value v, starting with dp[0] = 0. For each
    // value from 1 to V, we try adding each coefficient c[i] and update dp[v]
    // with the minimum count, returning - 1 if V is unreachable. The complexity
    // is trivially O(nV). The main observation here is that both n and V are
    // reasonably small.

    vector<int> dp(V + 1, INT_MAX);
    dp[0] = 0;

    for(int v = 1; v <= V; v++) {
        for(int i = 0; i < n; i++) {
            if(v >= c[i] && dp[v - c[i]] != INT_MAX) {
                dp[v] = min(dp[v], dp[v - c[i]] + 1);
            }
        }
    }

    if(dp[V] == INT_MAX) {
        cout << -1 << endl;
    } else {
        cout << dp[V] << endl;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        // cout << "Case #" << test << ": ";
        solve();
    }

    return 0;
}

=================
statement.txt
======================
248. Integer Linear Programming
time limit per test: 0.25 sec.
memory limit per test: 65536 KB
input: standard
output: standard



You are to solve some problem of integer linear programming. It is posed in the following way. Let x[i] be a variable which is required to be a non-negative integer (for any i from [1..N]). The goal is to minimize the function f(x[1], x[2],..., x[N])=x[1]+x[2]+...+x[N] (objective function) satisfying the constraint c[1]*x[1]+c[2]*x[2]+...+c[N]*x[N]=V.
The point X=(x[1], x[2],..., x[N]) that satisfies the constraint is called "feasible". All feasible points form a feasible set.
To make things clear, let us consider the following example N=2, c[1]=2, c[2]=4, V=6. There are only two feasible points: (1, 1) and (3, 0).
Clearly, the point (1, 1) is the optimal solution, because f(1, 1)<f(3, 0).

Input
The first line of input contains a single positive integer N (0<N<=3). The second line contains N positive integers c[i] separated by whitespaces (0<c[i]<=10^6). The last line contains positive integer V (0<V<=10^6).

Output
On the first line of the output file print the minimal possible value of the function f, or "-1" (without quotes) if the problem has no solution.

Sample test(s)

Input
Test #1
2
2 4
6

Test #2
2
7 4
9

Output
Test #1
2

Test #2
-1


=================
