SuperHyperMarket Gym - 100694E(优先队列)

久未见 提交于 2019-12-01 07:57:40

The day of opening of the greatest shop in the world is coming. To show the full potential of their shop, in particular, the unbelievable speed of the cash desks, the owners of the shop came up with the following move: n most average customers will be let into the shop, and the cash desks will be opened only after all customers will choose their purchases and take their places in the queues. The problem is that if the customers walk along the cash desks and choose the optimal queue, the process can last for several hours. That's why you are asked to choose queues for all customers automatically.

The sociologists told you how the average customers choose the queue: they look at the number of people in the queue and at the number of the purchases of the last two people in it. Formally, the customer chooses the cash desk i for which the value xi = ci·p is minimal. Here, ci is the number of people in the i-th queue, and p — is the average (by the average customer's definition) number of purchases of one person in the queue. The value of p is calculated by two last people in the queue: p = (p1 + p2) / 2, if there are two or more people in the queue (p1 and p2 are the numbers of purchases of the last two people), p = p1, if there is only one customer in the queue, and p = 0 if the queue is empty. If there are several cash desks with minimal xi, the customer chooses the one with the minimal number i.

After the customers choose their queue, they don't go anywhere out of it.

Input

The first line contains two space-separated integers n and k (1 ≤ n, k ≤ 105) — the number of customers and the number of cash desks in the shop.

The next line contains n space-separated integers pj (1 ≤ pj ≤ 1000) — the numbers of purchases of the j-th customer in the chronological order. Every customer chooses his queue before the next customer starts doing it.

Output

Write n space-separated integers in one line. The i-th number should be equal to the number of cash desk where the i-th customer will go using the criterion described in the problem.

Examples

Input
5 21 3 1 2 3
Output
1 2 1 1 2 
Input
5 71 3 1 2 3
Output
1 2 3 4 5 
典型的优先队列
 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 struct item
 6 {
 7     long long num, top, cou;
 8     double data;
 9     long long a[5];
10     bool operator < (const item& a) const
11     {
12         return data > a.data || (data==a.data && num>a.num);
13     }
14 }ite;
15 
16 priority_queue<item>str;
17 
18 int main()
19 {
20     long long n, k, i, x;
21     scanf("%lld %lld", &n, &k);
22     for(i=1; i<=n; i++)
23     {
24         scanf("%lld", &x);
25         if(i<=k)
26         {
27             printf("%lld", i);
28             ite.top = 0;
29             ite.num = i;
30             ite.cou = 1;
31             ite.a[ite.top++] = x;
32             ite.data = 1.0 * (ite.a[0] + ite.a[1]) / ite.top * ite.cou;
33         }
34         else
35         {
36             ite = str.top();
37             str.pop();
38             printf("%lld", ite.num);
39             ite.cou++;
40             if(ite.top<2)
41             {
42                 ite.a[ite.top++] = x;
43                 ite.data = 1.0 * (ite.a[0] + ite.a[1]) / ite.top * ite.cou;
44             }
45             else
46             {
47                 ite.a[0] = ite.a[1];
48                 ite.a[1] = x;
49                 ite.data = 1.0 * (ite.a[0] + ite.a[1]) / ite.top * ite.cou;
50             }
51         }
52         str.push(ite);
53         if(i==n) printf("\n");
54         else printf(" ");
55     }
56     return 0;
57 }
 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 struct item
 6 {
 7     long long num, top, cou;
 8     double data;
 9     long long a[5];
10     bool operator < (const item& a) const
11     {
12         return data > a.data || (data==a.data && num>a.num);
13     }
14 }ite;
15 
16 priority_queue<item>str;
17 
18 int main()
19 {
20     long long n, k, i, x;
21     scanf("%lld %lld", &n, &k);
22     for(i=1; i<=n; i++)
23     {
24         scanf("%lld", &x);
25         if(i<=k)
26         {
27             printf("%lld", i);
28             ite.top = 0;
29             ite.num = i;
30             ite.cou = 1;
31             ite.a[ite.top++] = x;
32             ite.data = 1.0 * (ite.a[0] + ite.a[1]) / ite.top * ite.cou;
33         }
34         else
35         {
36             ite = str.top();
37             str.pop();
38             printf("%lld", ite.num);
39             ite.cou++;
40             if(ite.top<2)
41             {
42                 ite.a[ite.top++] = x;
43                 ite.data = 1.0 * (ite.a[0] + ite.a[1]) / ite.top * ite.cou;
44             }
45             else
46             {
47                 ite.a[0] = ite.a[1];
48                 ite.a[1] = x;
49                 ite.data = 1.0 * (ite.a[0] + ite.a[1]) / ite.top * ite.cou;
50             }
51         }
52         str.push(ite);
53         if(i==n) printf("\n");
54         else printf(" ");
55     }
56     return 0;
57 }

 

 
 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!