466B - Wonder Room - CodeForces Solution


brute force math *2000

Please click on ads to support us..

Python Code:

import sys
input = sys.stdin.readline

def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))

def Wonder_Room():
    import math
    n,a,b = invr()

    min_area_reqd = 6*n 

    if min_area_reqd <= (a*b):
        print(a*b)
        print(str(a) + ' ' + str(b))
    
    else:
        max_room_size = int(math.sqrt(min_area_reqd)) + 1

        min_area = -1 
        corresponding_a = -1
        corresponding_b = -1

        if a < b: 
            room1_size_min = a 
            room2_size_min = b 
        else:
            room1_size_min = b 
            room2_size_min = a 

        for room1_size in range(room1_size_min,max_room_size):
            room2_size = math.ceil(min_area_reqd/room1_size)
            current_area = room1_size * room2_size

            if room2_size >= room2_size_min and min_area == -1:
                min_area = current_area

                if a<b:
                    corresponding_a = room1_size
                    corresponding_b = room2_size
                else:
                    corresponding_b = room1_size
                    corresponding_a = room2_size

            elif room2_size >= room2_size_min  and current_area < min_area:
                min_area = current_area

                if a < b:
                    corresponding_a = room1_size
                    corresponding_b = room2_size
                else:
                    corresponding_b = room1_size
                    corresponding_a = room2_size
        
        print(min_area)
        print(str(corresponding_a) + ' ' + str(corresponding_b))
    
    return

Wonder_Room()


Comments

Submit
0 Comments
More Questions

Number of triangles
AND path in a binary tree
Factorial equations
Removal of vertices
Happy segments
Cyclic shifts
Zoos
Build a graph
Almost correct bracket sequence
Count of integers
Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses