import java.util.Arrays; import java.util.HashMap; import java.util.LinkedList; import java.util.Scanner; public class Main { public static long get_sum(int lx, int ly, int rx, int ry, long[][] sums){ final long ll = (lx == 0 || ly == 0) ? 0 : sums[ly - 1][lx - 1]; final long lr = ly == 0 ? 0 : sums[ly - 1][rx]; final long rl = lx == 0 ? 0 : sums[ry][lx - 1]; final long rr = sums[ry][rx]; return rr - rl - lr + ll; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); final int N = sc.nextInt(); final long B = sc.nextLong(); long[] xs = new long[N]; long[] ys = new long[N]; long[] ps = new long[N]; for(int i = 0; i < N; i++){ xs[i] = sc.nextLong(); ys[i] = sc.nextLong(); ps[i] = sc.nextLong(); } long[] sorted_x = xs.clone(); long[] sorted_y = ys.clone(); Arrays.sort(sorted_x); Arrays.sort(sorted_y); HashMap x_to_index = new HashMap(); HashMap y_to_index = new HashMap(); for(int i = 0; i < N; i++){ x_to_index.put(sorted_x[i], i); y_to_index.put(sorted_y[i], i); } long[][] sorted_sum = new long[N][N]; long[][] sorted_cnt = new long[N][N]; for(int i = 0; i < N; i++){ final int x_index = x_to_index.get(xs[i]); final int y_index = y_to_index.get(ys[i]); sorted_sum[y_index][x_index] = ps[i]; sorted_cnt[y_index][x_index]++; } for(int y = 0; y < N; y++){ for(int x = 0; x < N; x++){ if(x != 0 && y != 0){ sorted_sum[y][x] += sorted_sum[y - 1][x] + sorted_sum[y][x - 1] - sorted_sum[y - 1][x - 1]; sorted_cnt[y][x] += sorted_cnt[y - 1][x] + sorted_cnt[y][x - 1] - sorted_cnt[y - 1][x - 1]; }else if(x != 0){ sorted_sum[y][x] += sorted_sum[y][x - 1]; sorted_cnt[y][x] += sorted_cnt[y][x - 1]; }else if(y != 0){ sorted_sum[y][x] += sorted_sum[y - 1][x]; sorted_cnt[y][x] += sorted_cnt[y - 1][x]; } } } //System.out.println(Arrays.deepToString(sorted_sum)); //System.out.println(Arrays.deepToString(sorted_cnt)); long answer = 0; for(int x_upper = 0; x_upper < N; x_upper++){ for(int x_lower = 0; x_lower <= x_upper; x_lower++){ int y_upper = 0; for(int y_lower = 0; y_lower < N; y_lower++){ //System.out.printf("(%d, %d) : (%d, %d)\n", x_lower, y_lower, x_upper, y_upper); final long cnt = get_sum(x_lower, y_lower, x_upper, y_upper, sorted_cnt); final long value = get_sum(x_lower, y_lower, x_upper, y_upper, sorted_sum); //System.out.println(value); if(cnt > 0 && value <= B){ //System.out.println(cnt); answer = Math.max(answer, cnt); if(y_upper < N - 1){ y_upper++; y_lower--;} }else{ if(y_upper < N - 1){ y_upper++; } } } } } System.out.println(answer); } }