Tap here to switch tabs
Problem
Submissions

Problem: Coordinate With Maximum Network Quality

med
30 min
Try to solve the Coordinate With Maximum Network Quality problem.

Statement

You are given an array towers where towers[i] = [xix_i, yiy_i, qiq_i] denotes the location ((xix_i, yiy_i)) and the network quality qiq_i of the iextthi^{ ext{th}} tower. You are also given an integer radius.

The network quality contribution of tower ii to an integral coordinate (x,y)(x, y) is calculated as ⌊qi1+d⌋\lfloor \frac{q_i}{1 + d} \rfloor, where dd is the Euclidean distance between (x,y)(x, y) and ((xix_i, yiy_i)), provided that d≤d \le radius. If d>d > radius, the tower provides no quality to that coordinate.

The total network quality at coordinate (x,y)(x, y) is the sum of the quality contributions from all towers within distance radius.

Return the integral coordinate [x,y][x, y] with x≥0x \ge 0 and y≥0y \ge 0 that achieves the maximum total network quality. If multiple coordinates share the same maximum quality, return the lexicographically smallest coordinate.

Note: A coordinate (x1,y1)(x_1, y_1) is lexicographically smaller than (x2,y2)(x_2, y_2) if x1<x2x_1 < x_2, or if x1=x2x_1 = x_2 and y1<y2y_1 < y_2. The floor function ⌊val⌋\lfloor val \rfloor rounds valval down to the nearest integer.

Constraints:

  • 1≤1 \leq towers.length ≤50\leq 50

  • towers[i].length =3= 3

  • 0≤xi,yi,qi≤500 \leq x_i, y_i, q_i \leq 50

  • 1≤1 \leq radius ≤50\leq 50

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Coordinate With Maximum Network Quality

med
30 min
Try to solve the Coordinate With Maximum Network Quality problem.

Statement

You are given an array towers where towers[i] = [xix_i, yiy_i, qiq_i] denotes the location ((xix_i, yiy_i)) and the network quality qiq_i of the iextthi^{ ext{th}} tower. You are also given an integer radius.

The network quality contribution of tower ii to an integral coordinate (x,y)(x, y) is calculated as ⌊qi1+d⌋\lfloor \frac{q_i}{1 + d} \rfloor, where dd is the Euclidean distance between (x,y)(x, y) and ((xix_i, yiy_i)), provided that d≤d \le radius. If d>d > radius, the tower provides no quality to that coordinate.

The total network quality at coordinate (x,y)(x, y) is the sum of the quality contributions from all towers within distance radius.

Return the integral coordinate [x,y][x, y] with x≥0x \ge 0 and y≥0y \ge 0 that achieves the maximum total network quality. If multiple coordinates share the same maximum quality, return the lexicographically smallest coordinate.

Note: A coordinate (x1,y1)(x_1, y_1) is lexicographically smaller than (x2,y2)(x_2, y_2) if x1<x2x_1 < x_2, or if x1=x2x_1 = x_2 and y1<y2y_1 < y_2. The floor function ⌊val⌋\lfloor val \rfloor rounds valval down to the nearest integer.

Constraints:

  • 1≤1 \leq towers.length ≤50\leq 50

  • towers[i].length =3= 3

  • 0≤xi,yi,qi≤500 \leq x_i, y_i, q_i \leq 50

  • 1≤1 \leq radius ≤50\leq 50