Skip to content

Instantly share code, notes, and snippets.

@msg555
Last active December 11, 2015 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msg555/4645079 to your computer and use it in GitHub Desktop.
Save msg555/4645079 to your computer and use it in GitHub Desktop.
Solution to Buying Hay (hay)
#include <iostream>
#include <cstring>
using namespace std;
int DP[50010];
int main() {
int N, H;
cin >> N >> H;
memset(DP, 0x3F, sizeof(DP));
for(int i = DP[0] = 0; i < N; i++) {
int P, C; cin >> P >> C;
for(int i = 1; i <= H; i++) {
DP[i] = min(DP[i], C + DP[max(0, i - P)]);
}
}
cout << DP[H] << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment