#include<iostream> #include<algorithm> using namespace std; struct bucket { public: int apple; int pear; int no; bool operator < (const bucket& b) { if (apple < b.apple)return true; else if(apple == b.apple && pear < b.pear) return true; else if (apple == b.apple && pear == b.pear && no > b.no)return true; return false; } bool operator == (const bucket& b) { return apple == b.apple && pear == b.pear && no == b.no; } }; int main() { int t, n, m; cin >> t; while (t--) { cin >> n >> m; bucket* buckets = new bucket[n]; for (int i = 0; i < n; ++i) { cin >> buckets[i].apple >> buckets[i].pear; buckets[i].no = i + 1; } sort(buckets, buckets + n); for (int i = n - 1; i >= n - m; --i) { cout << buckets[i].no; if (i != n - m)cout << ' '; } if (t != 0)cout << endl; delete[] buckets; } return 0; } |
Double click to view unformatted code.