fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MAX_LENGTH = 100;
  5. const int MAX_VALUE = 10000000;
  6.  
  7. int main() {
  8. int n, planet[MAX_LENGTH + 1], people[MAX_LENGTH + 1];
  9. cin >> n;
  10. int x = 1;
  11. while (x <= n) {
  12. cin >> planet[x];
  13. cin >> people[x];
  14. //cout << planet[x] <<" " << people[x] <<" " << x << "\n";
  15. ++x;
  16. }
  17. while (x > 1) {
  18. int index = 1;
  19. int highVal = 0, highPeo = MAX_VALUE;
  20. for (int i = 1; i <= n; ++i) {
  21. if (planet[i] > highVal && planet[i] != -1) {
  22. highVal = planet[i];
  23. highPeo = people[i];
  24. index = i;
  25. } else if (planet[i] == highVal && people[i] < highPeo ) {
  26. highVal = planet[i];
  27. highPeo = people[i];
  28. index = i;
  29. }
  30. }
  31. //cout << planet[index] <<" " << people[index] <<" " << index << "\n";
  32. cout << index <<" ";
  33. planet[index] = -1;
  34. people[index] = -1;
  35. --x;
  36. }
  37. return 0;
  38. }
Success #stdin #stdout 0.01s 5324KB
stdin
6
1 6
0 19
0 15
9 123456
1 99
6 123

6
1 6 -1
0 19
0 15
9 123456 -1
1 99 -1
6 123 -1
stdout
4 6 1 5 3 2