2016 Feb Bronze Problem 3 Load Balancing: Difference between revisions

From Wiki
Jump to navigation Jump to search
Line 6: Line 6:


== Solution ==
== Solution ==
import sys
the input B is not used in this situation, instead you find every possible x and y coordinates of the fence by adding 1 on each x and y input
 
sys.stdin = open("balancing.in", "r")
sys.stdout = open("balancing.out", "w")
 
n,b = map(int,input().split())
 
x_val = []
y_val = []
x_fen = []
h_fen = []
 
for _ in range(n):
x, y = map(int,input().split())
x_val.append(x)
y_val.append(y)
x_fen.append(x + 1) 
h_fen.append(x + 1)
min_balance = n
 
for v_y in x_fen:
for h_x in h_fen:
tl,tr,bl,br = 0,0,0,0
for k in range(n):
x,y = x_val[k],y_val[k]
if x > h_x and y > v_y:
tl+=1
elif x < h_x and y > v_y:
tr+=1
elif x > h_x and y < v_y:
bl+=1
else:
br+=1
 
min_balance = min(min_balance, max(tl,tr,bl,br))
 
print(min_balance)


== Code ==
== Code ==

Revision as of 14:10, 10 January 2024

Official Problem Statement

Load Balancing

Problem

Solution

the input B is not used in this situation, instead you find every possible x and y coordinates of the fence by adding 1 on each x and y input

Code

import sys

sys.stdin = open("balancing.in", "r") sys.stdout = open("balancing.out", "w")

n,b = map(int,input().split())

x_val = [] y_val = [] x_fen = [] h_fen = []

for _ in range(n): x, y = map(int,input().split()) x_val.append(x) y_val.append(y) x_fen.append(x + 1) h_fen.append(x + 1)

min_balance = n

for v_y in x_fen: for h_x in h_fen:

tl,tr,bl,br = 0,0,0,0 for k in range(n): x,y = x_val[k],y_val[k] if x > h_x and y > v_y: tl+=1 elif x < h_x and y > v_y: tr+=1 elif x > h_x and y < v_y: bl+=1 else: br+=1

min_balance = min(min_balance, max(tl,tr,bl,br))

print(min_balance)