#include <cstdio> #include <algorithm> using namespace std; struct node { int a, b; int idx; }; bool cmp(const node &A, const node &B){ if (A.a == B.a) { if (A.b == B.b) { return A.idx < B.idx; } return A.b > B.b; } return A.a > B.a; } int main(){ int t; int n, m; node bucket[100000]; scanf("%d", &t); while (t--) { scanf("%d%d", &n, &m); for (int i = 0; i < n; i ++) { scanf("%d%d", &bucket[i].a, &bucket[i].b); bucket[i].idx = i+1; } sort(bucket, bucket+n, cmp); for (int i = 0; i < m-1; i ++) { printf("%d ", bucket[i].idx); } printf("%d\n",bucket[m-1].idx); } return 0; } |
Double click to view unformatted code.