CF572B.Order Book

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

In this task you need to process a set of stock exchange orders and use them to create order book.

An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number i has price p__i, direction d__i — buy or sell, and integer q__i. This means that the participant is ready to buy or sell q__i stocks at price p__i for one stock. A value q__i is also known as a volume of an order.

All orders with the same price p and direction d are merged into one aggregated order with price p and direction d. The volume of such order is a sum of volumes of the initial orders.

An order book is a list of aggregated orders, the first part of which contains sell orders sorted by price in descending order, the second contains buy orders also sorted by price in descending order.

An order book of depth s contains s best aggregated orders for each direction. A buy order is better if it has higher price and a sell order is better if it has lower price. If there are less than s aggregated orders for some direction then all of them will be in the final order book.

You are given n stock exhange orders. Your task is to print order book of depth s for these orders.

在本任务中,你需要处理一组股票交易所的委托单,并利用它们构建一个订单簿(order book)。

一条委托单(order)是某位市场参与者在股票交易所下达的买入或卖出股票的指令。第 ii 条委托单具有价格 pip_i、方向 did_i(买入或卖出)以及整数 qiq_i。这意味着该参与者愿意以每股 pip_i 的价格买入或卖出 qiq_i 股股票。数值 qiq_i 也被称为该委托单的“成交量”(volume)。

所有价格相同(均为 pp)且方向相同(均为 dd)的委托单将被合并为一条聚合委托单(aggregated order),其价格为 pp、方向为 dd;该聚合委托单的成交量等于所有原始委托单成交量之和。

订单簿是一个由聚合委托单构成的列表:前半部分为卖单,按价格降序排列;后半部分为买单,也按价格降序排列。

深度为 ss 的订单簿(order book of depth ss)包含每个方向上最优的 ss 条聚合委托单。对买单而言,“更优”意味着价格更高;对卖单而言,“更优”意味着价格更低。若某一方向上的聚合委托单总数少于 ss 条,则订单簿中将包含该方向的所有聚合委托单。

现给你 nn 条股票交易所委托单。你的任务是输出这些委托单所对应的深度为 ss 的订单簿。

输入格式

The input starts with two positive integers n and s (1 ≤ n ≤ 1000, 1 ≤ s ≤ 50), the number of orders and the book depth.

Next n lines contains a letter d__i (either 'B' or 'S'), an integer p__i (0 ≤ p__i ≤ 105) and an integer q__i (1 ≤ q__i ≤ 104) — direction, price and volume respectively. The letter 'B' means buy, 'S' means sell. The price of any sell order is higher than the price of any buy order.

输入的第一行包含两个正整数 nn 和 ss(1 ≤ n ≤ 10001 \le n \le 1000,1 ≤ s ≤ 501 \le s \le 50),分别表示订单数量和盘口深度。

接下来的 nn 行,每行包含一个字母 did_i(为 'B' 或 'S')、一个整数 pip_i(0 ≤ pi ≤ 1050 \le p_i \le 10^5)和一个整数 qiq_i(1 ≤ qi ≤ 1041 \le q_i \le 10^4),分别表示订单方向、价格和数量。字母 'B' 表示买入,'S' 表示卖出。任意卖单的价格均高于任意买单的价格。

输出格式

Print no more than 2_s_ lines with aggregated orders from order book of depth s. The output format for orders should be the same as in input.

最多打印 2s2s 行来自深度为 ss 的订单簿的聚合订单。订单的输出格式应与输入格式相同。

输入输出样例

  • 输入#1

    6 2
    B 10 3
    S 50 2
    S 40 1
    S 50 6
    B 20 4
    B 25 10

    输出#1

    S 50 8
    S 40 1
    B 25 10
    B 20 4

说明/提示

Denote (x, y) an order with price x and volume y. There are 3 aggregated buy orders (10, 3), (20, 4), (25, 10) and two sell orders (50, 8), (40, 1) in the sample.

You need to print no more than two best orders for each direction, so you shouldn't print the order (10 3) having the worst price among buy orders.

用 (x,y)(x, y) 表示一个订单,其中价格为 xx,数量为 yy。样例中包含 3 个聚合的买入订单:(10,3)(10, 3)、(20,4)(20, 4)、(25,10)(25, 10),以及 2 个卖出订单:(50,8)(50, 8)、(40,1)(40, 1)。

你需要为每个方向(买入和卖出)最多输出两个最优订单,因此不应输出买入订单中价格最差的订单 (10, 3)(10,\ 3)。

输入解题思路,AI测评打分。不知道怎么写?

首页