range queries and one graph
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
// Minimizing Coins
|
||||
|
||||
#include<bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
int n, x;
|
||||
cin >> n >> x;
|
||||
vector<int> dp(x + 1, INT_MAX - 5);
|
||||
dp[0] = 0;
|
||||
for (int i{}; i < n; i++) {
|
||||
int c; cin >> c;
|
||||
for (int j = c; j <= x; j++) {
|
||||
if (j >= c) {
|
||||
dp[j] = min(dp[j - c] + 1, dp[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dp[x] != INT_MAX - 5) cout << dp[x] << endl;
|
||||
else cout << -1 << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user