#include <iostream> #include <algorithm> using namespace std; struct bucket { int apple, pear, ind; }; bool cmp(const bucket &a, const bucket &b) { if (a.apple == b.apple) { if (a.pear == b.pear) { return a.ind < b.ind; } return a.pear > b.pear; } return a.apple > b.apple; } int main() { int t, n, m; cin >> t; while (t--) { cin >> n >> m; bucket bck[100005]; for (int i = 0; i < n; i++) { cin >> bck[i].apple >> bck[i].pear; bck[i].ind = i; } sort(bck, bck + n, cmp); for (int i = 0; i < m; i++) { if (i != 0) { cout << " "; } cout << bck[i].ind; } } return 0; } |
Double click to view unformatted code.