/* -*- coding: utf-8 -*- * * 2093.cc: No.2093 Shio Ramen - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 1000; const int MAX_S = 1000; /* typedef */ /* global variables */ int ss[MAX_N], as[MAX_N]; int dp[MAX_S + 1]; /* subroutines */ inline void setmax(int &a, int b) { if (a < b) a = b; } /* main */ int main() { int n, s; scanf("%d%d", &n, &s); for (int i = 0; i < n; i++) scanf("%d%d", ss + i , as + i); fill(dp, dp + s + 1, -1); dp[0] = 0; for (int i = 0; i < n; i++) for (int j = s - ss[i]; j >= 0; j--) if (dp[j] >= 0) setmax(dp[j + ss[i]], dp[j] + as[i]); int maxd = 0; for (int j = 0; j <= s; j++) setmax(maxd, dp[j]); printf("%d\n", maxd); return 0; }