Educational Codeforces Roud 152[Div.2] B题

Problem - B - Codeforces

Monocarp is playing yet another computer game. And yet again, his character is killing some monsters. There are n monsters, numbered from 11 to n, and the i-th of them has aihealth points initially.

Monocarp's character has an ability that deals k damage to the monster with the highest current health. If there are several of them, the one with the smaller index is chosen. If a monster's health becomes less than or equal to 00 after Monocarp uses his ability, then it dies.

Monocarp uses his ability until all monsters die. Your task is to determine the order in which monsters will die.

Input

The first line contains a single integer t(1≤t≤10的四次方) — the number of test cases.

The first line of each test case contains two integers n and k (1≤n≤3⋅10的五次方; 1≤k≤10的九次方) — the number of monsters and the damage which Monocarp's ability deals.

The second line contains n integers a1,a2,…,an (1≤ai≤10的九次方) — the initial health points of monsters.

The sum of n over all test cases doesn't exceed 3⋅1053⋅105.

Output

For each test case, print n integers — the indices of monsters in the order they die.

Example

input

3

3 2

1 2 3

2 3

1 1

4 3

2 8 3 5

output

2 1 3 1 2 3 1 2 4

Note

In the first example, the health points change as follows: [1,2,3–]→[1,2–,1]→[1–,0,1]→[−1,0,1–]→[−1,0,−1][1,2,3_]→[1,2_,1]→[1_,0,1]→[−1,0,1_]→[−1,0,−1]. The monster that is going to take damage the next time Monocarp uses his ability is underlined.

In the second example, the health points change as follows: [1–,1]→[−2,1–]→[−2,−2][1_,1]→[−2,1_]→[−2,−2].

In the third example, the health points change as follows: [2,8–,3,5]→[2,5–,3,5]→[2,2,3,5–]→[2,2,3–,2]→[2–,2,0,2]→[−1,2–,0,2]→[−1,−1,0,2–]→[−1,−1,0,−1][2,8_,3,5]→[2,5_,3,5]→[2,2,3,5_]→[2,2,3_,2]→[2_,2,0,2]→[−1,2_,0,2]→[−1,−1,0,2_]→[−1,−1,0,−1].

#include<bits/stdc++.h>
using namespace std;
struct M
{
	int d,id;
}a[3000005];
bool cmp(M a,M b)
{
	if(a.d!=b.d ) return a.d>b.d;
	return a.id<b.id;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i].d;
			a[i].d%=k;
			if(a[i].d==0) a[i].d=k;
			a[i].id=i;
		}
		sort(a+1,a+n+1,cmp);
		for(int i=1;i<=n;i++)
		cout<<a[i].id<<" ";
		cout<<endl;
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值