(algorithm Getting Started Classic tournament priority queue) LA 3135 (previous K description)

Source: Internet
Author: User

A data stream is a real-time, continuous, ordered sequence of items. Some examples include sensor data, Internet traffic, financial tickers, on-line auctions, and transaction logs such as Web Usage logs and telephone call records. Likewise, queries over streams run continuously over a period of time and incrementally return new results as new data arr Ives. For example, a temperature detection system of a factory warehouse if run queries like the following.

Query-1:? Every five minutes, retrieve the maximum temperature over the past five minutes.? Query-2:? Return the average temperature measured on all floor over the past minutes.?

We have developed a data Stream Management System called Argus and which processes the queries over the data streams. Users can register queries to the Argus. Argus would keep the queries running over the changing data and return the results-the corresponding user with the Desir Ed frequency.

For the Argus, we use the following instruction to register a query:

Register q_num Period

Q_num (0 < q_num≤3000) is a query id-number, and Period (0 < period≤3000) is the interval between the consecutive Returns of the result. After Period seconds of register, the result would be returned for the first time, and after, the result would be retur Ned every Period seconds.

Here we have the several different queries registered in Argus at once. It is confirmed and all the queries has different q_num. Your task is to tell the first K queries to return the results. If or more queries is to return the results at the same time, they'll return the results one by one in the Ascendin G Order of Q_num.

Input

The first part of the input is the register instructions to Argus, one instruction per line. You can assume the number of the instructions would not be exceed, and all these instructions is executed at the same ti Me. This was ended with a line of #?.

The second part is your task. This part contains only one line, which is one positive integer K (≤10000).

Output

You should output the q_num of the first K queries to return the results, one number per line.

Sample Input
Register 2004 200Register 2005 300#5

Sample Output
20042005200420042005


The code is as follows:

/* * la_3135.cpp * *  Created on:2014 August 1 *      author:pc * * #include <iostream> #include <cstdio> #includ E <queue>using namespace std;struct item{int num;//instruction ordinal int period;//instruction run period int time;//instruction next Run time bool operator < (const item& B) const{if (Time! = B.time) {return time > b.time;} return num > B.num;}}; int main () {char s[20];p riority_queue<item> pq;while (scanf ("%s", &s), s[0]! = ' # ') {Item item;scanf ("%d%d", &item.num,&item.period); item.time = Item.period;pq.push (item);} int k;scanf ("%d", &k), while (k--) {//Core logic Item R = Pq.top ();//constantly take out and then keep plugging Pq.pop ();p rintf ("%d\n", r.num); R.time + = R.period;pq.push (r);} return 0;}



(algorithm Getting Started Classic tournament priority queue) LA 3135 (previous K description)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.