Rated Contest 3 P4 - Graph Theory

View as PDF

Submit solution

Points: 10 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

Oops! You and your co-op member just got scammed of all your valuables in Hypixel Skyblock, and you need to get it back. Thankfully, from previous investments for the Crimson Isle update, and Auction House flipping, you are still stacked with coins. Skyblock lets you buy and sell resources using the Bazaar. The Bazaar acts like a stock market, where item prices are based on supply, demand, and of course, value.

You have N items you would like to purchase. For any item on the Bazaar, there are two methods you can use to purchase it: Insta-buy and Buy order. Insta-buy is in the name; you receive the items the moment you purchase them, for A_i coins. Buy orders allow you to purchase the items at a lower cost than insta-buying, at B_i coins. However, buy orders require you to wait for another player to sell that item, so it can fill your order. As a result, it often takes some time, C_i, to receive your item.

Due to your co-op member taking up all the bazaar buy slots, you are only able to have 1 pending buy order at a time. The Bazaar is an extremely volatile market, and prices change in T minutes. Within T minutes, what is the minimum amount of coins you must pay to obtain all N items? As well, which items should you insta-buy and which ones should you make a buy order for?

Subtasks

1 \leq N,T \leq 10^3

1 \leq A_i,B_i,C_i \leq 10^9

|S_i| < 100, and will only contain alphanumeric characters and _.

Subtask 1 [30%]

1 \leq N,T \leq 10

Subtask 2 [70%]

No further constraints.

Input Specifications

The first line contains space separated integers N, and T.

The next N lines will contain a string S_i, the name of the item, then followed by space separated integers A_i,B_i,C_i. A_i is the insta-buy price, while B_i is the buy order price, and C_i is the number of minutes it will take for that order to fill if you purchase with a buy order.

Output Specifications

On the first line, output the minumum amount of coins required to purchase all items. For the next N lines, for each item i, output the item name, and then insta-buy if you will insta-buy the item, or buy order if you will make a buy order for the item.

Sample Input

5 10
Fine_Ruby_Gemstone 2000 1500 3
Turbo_Wheat_I 12000 10500 1
Kuudra_Teeth 6000 5000 4
Enchanted_Mycelium 3000 2750 2
Enchanted_Mithril 7000 5000 6

Sample Output

26000
Fine_Ruby_Gemstone buy order
Turbo_Wheat_I buy order
Kuudra_Teeth insta-buy
Enchanted_Mycelium insta-buy
Enchanted_Mithril buy order

Explanation for Sample Output

By setting buy orders for Fine Ruby Gemstone, Turbo Wheat I, and Enchanted Mithril, you will save 4000 coins, and take 3+1+6 = 10 minutes, which does not exceed T. It can be shown that 4000 is the most amount of coins you can save.


Comments

There are no comments at the moment.