Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.FileNotFoundException;
- import java.io.PrintWriter;
- import java.util.Arrays;
- import java.util.Scanner;
- public class ratattack {
- public void run() {
- int T = in.nextInt();
- for (int t = 1; t <= T; t++) {
- int d = in.nextInt();
- int n = in.nextInt();
- int[][] grid = new int[1025][1025];
- for (int i = 0; i < n; i++) {
- int X = in.nextInt();
- int Y = in.nextInt();
- int pop = in.nextInt();
- for (int x = X - d; x <= X + d; x++) {
- for (int y = Y - d; y <= Y + d; y++) {
- try {
- grid[x][y] += pop;
- } catch (Exception e) {
- }
- }
- }
- }
- int m = grid[0][0];
- int X = 0;
- int Y = 0;
- for (int x = 0; x < 1025; x++) {
- for (int y = 0; y < 1025; y++) {
- if (grid[x][y] > m) {
- m = grid[x][y];
- X = x;
- Y = y;
- }
- }
- }
- System.out.println(X + " " + Y + " " + m);
- }
- }
- public void debug(Object n) {
- System.out.println("\t\tDEBUG\t\t" + n.toString().replace("\n", "\n\t\tDEBUG\t\t"));
- }
- static Scanner in = new Scanner(System.in);
- static PrintWriter out = new PrintWriter(System.out);
- public static void main(String[] args) throws FileNotFoundException {
- // in = new Scanner(new File("ratattack.in"));
- // out = new PrintWriter(new File("ratattack.out"));
- (new ratattack()).run();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement