#include using namespace std; using Int = long long; template inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template inline void chmax(T1 &a,T2 b){if(a>n>>d; vector t(n),k(n); for(Int i=0;i>t[i]>>k[i]; const Int INF = 1e15; Int dp[2][1010]; for(Int i=0;i<1010;i++) dp[0][i]=dp[1][i]=-INF; dp[0][0]=0; for(Int i=0;i