Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <limits>
- using namespace std;
- int solve(vector<int> &V, int k, int sum, int i) {
- if (sum >= k) return sum;
- if (i == V.size()) return numeric_limits<int>::max();
- int eat = solve(V, k, sum + V.at(i), i + 1);
- int no_eat = solve(V, k, sum, i + 1);
- return min (eat, no_eat);
- }
- int main() {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- int N, K;
- cin >> N >> K;
- vector<int> V(N);
- for (int &x : V) {
- cin >> x;
- }
- cout << solve(V, K, 0, 0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement