#include #define fi first #define se second #define pb push_back #define CLR(A, X) memset(A, X, sizeof(A)) using namespace std; typedef long long LL; typedef pair PII; typedef pair PLL; const double eps = 1e-10; int dcmp(double x){if(fabs(x) d) { int x = ski[i].se-d; for(int h = 0; h < x; h++) { if(dp[h][d] == -1) dp[h][d] = ski[i].fi; else dp[h][d] = min(dp[h][d], ski[i].fi); } for(int h = x; h <= 1000; h++) if(dp[h-x][d] != -1) { if(dp[h][d] == -1) dp[h][d] = dp[h-x][d]+ski[i].fi; else dp[h][d] = min(dp[h][d], dp[h-x][d]+ski[i].fi); } } } for(int d = 0; d <= 10; d++) { for(int h = 1000; h >= 1; h--) { if(dp[h-1][d] == -1) dp[h-1][d] = dp[h][d]; else dp[h-1][d] = min(dp[h-1][d], dp[h][d]); } } bool flag = 1; LL ans = 0; for(int i = 0; i < n; i++) { if(dp[mon[i].fi][mon[i].se] == -1) { flag = 0; break; } ans += dp[mon[i].fi][mon[i].se]; // printf("? = %d %d %lld\n", mon[i].fi, mon[i].se, dp[mon[i].fi][mon[i].se]); } if(!flag) ans = -1; printf("%lld\n", ans); } return 0; }