import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public class Node{ public int la; public int lo; public int height; public int points; public Node(int la,int lo, int height, int points){ this.la = la; this.lo = lo; this.height = height; this.points = points; } public boolean isAllowed(Node target,int maxX, int maxY){ if (Math.abs(target.la - la)> maxX){ return false; } if (Math.abs(target.lo - lo)> maxY){ return false; } if (target.height < height){ return false; } return true; } } public Node createNode(int la,int lo, int height, int points){ return this.new Node(la, lo, height, points); } public static void main(String[] args) { Solution dl = new Solution(); Scanner in = new Scanner(System.in); int n = in.nextInt(); int x = in.nextInt(); int y = in.nextInt(); ArrayList listOfArray = new ArrayList(); for(int a0 = 0; a0 < n; a0++){ int latitude = in.nextInt(); int longitude = in.nextInt(); int height = in.nextInt(); int points = in.nextInt(); // your code goes here listOfArray.add(dl.createNode(latitude,longitude,height,points)); } Node Highest = listOfArray.get(0); for (Node cur : listOfArray){ if (cur.points < Highest.points){ Highest = cur; } } int result = visit(listOfArray,Highest,x,y,n); System.out.print(5); } public static int visit( ArrayList listOfArray ,Node start,int maxX, int maxY, int step){ step = step-1; if (step <=0 || listOfArray.isEmpty()){ return 0; } listOfArray.remove(start); Node Highest = start; for (Node cur : listOfArray){ if (cur.points < Highest.points && cur.isAllowed(start,maxX,maxY)){ Highest = cur; } } return start.height+ visit(listOfArray,Highest,maxX,maxY,step); } }