Last active
December 11, 2015 18:58
-
-
Save msg555/4645079 to your computer and use it in GitHub Desktop.
Solution to Buying Hay (hay)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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