Description
Submission
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> solve(vector<int> nums, int k)
{
vector<pair<int,int>> num_pairs(nums.size());
for(int i = 0; i < nums.size(); ++i) {
num_pairs[i] = make_pair(i, nums[i]);
}
sort(num_pairs.begin(), num_pairs.end(), [k](pair<int, int>& p1, pair<int, int>& p2) {
if((p1.second - 1) / k == (p2.second - 1) / k) return p1.first < p2.first;
return p1.second < p2.second;
});
for(int i = 0; i < num_pairs.size(); ++i) {
nums[i] = num_pairs[i].first + 1;
}
return nums;
}
int main() {
int T; cin >> T;
for(int Ti = 0; Ti < T; ++Ti) {
int N, X; cin >> N >> X;
vector<int> A(N);
for(int Ni = 0; Ni < N; ++Ni) {
cin >> A[Ni];
}
auto res = solve(A, X);
cout << "Case #" << Ti + 1 << ":";
for(int i = 0; i < res.size(); ++i) {
cout << " " << res[i];
}
if(Ti != T-1) cout << " \n";
}
return 0;
}