|
|
вернуться в форумWA5 Python class MemoryManager: def __init__(self, n, t): self.n = n self.t = t self.blocks = {} self.free_blocks = set(range(1, n + 1)) def allocate_block(self, time): block = min(self.free_blocks) self.free_blocks.remove(block) self.blocks[block] = time + self.t return block def access_block(self, time, block_no): if block_no in self.blocks and self.blocks[block_no] >= time: return '+' else: return '-' n = 30000 t = 10 memory_manager = MemoryManager(n, t) queries = input().strip() for query in queries: query_type = query[0] time = query[1] if query_type == '+': print(memory_manager.allocate_block(time)) elif query_type == '.': block_no = query[2] print(memory_manager.access_block(time, block_no)) |
|
|