#include <iostream> #include <algorithm> using namespace std; struct Basket { int id; // 篮子编号 int apples; // 苹果数量 int pears; // 梨子数量 bool operator<(const Basket& other) const { if (apples != other.apples) { return apples > other.apples; } else if (pears != other.pears) { return pears > other.pears; } else { return id < other.id; } } }; Basket baskets[100010]; int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> baskets[i].apples >> baskets[i].pears; baskets[i].id = i + 1; } sort(baskets, baskets + n); for (int i = 0; i < m - 1; i++) { cout << baskets[i].id << " "; } cout << baskets[m-1].id << endl; } return 0; } |
Double click to view unformatted code.