fn main() { let mut ni = String::new(); std::io::stdin().read_line(&mut ni).ok(); let ni: Vec = ni.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let n = ni[0]; let t = ni[1]; let items = (0..n).map(|_| { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); (temp[0], temp[1]) }) .collect::>(); let mut dp = vec![vec![0usize; t+1]; n+1]; for i in 0..n { let (s, a) = items[i]; for j in 0..=t { dp[i+1][j] = dp[i+1][j].max(dp[i][j]); if j+s <= t { dp[i+1][j+s] = dp[i+1][j+s].max(dp[i][j] + a); } } } println!("{}", dp[n][t]); }