E.cpp 820 B

123456789101112131415161718192021222324252627282930
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. struct A{
  4. int chinese, math, english, total;
  5. int number;
  6. bool operator<(const A& other)const {
  7. if(total != other.total)
  8. return total > other.total;
  9. if(chinese != other.chinese)
  10. return chinese > other.chinese;
  11. return number < other.number;
  12. }
  13. };
  14. int main() {
  15. ifstream cin("scholar.in");
  16. ofstream cout("scholar.out");
  17. int n;
  18. cin >> n;
  19. vector<A>v(n);
  20. for(int i = 0; i < n; i++){
  21. cin >> v[i].chinese >> v[i].math >> v[i].english;
  22. v[i].total = v[i].chinese + v[i].math + v[i].english;
  23. v[i].number = i+1;
  24. }
  25. sort(v.begin(), v.end());
  26. for(int i = 0; i < 5 && i < v.size(); i++ ){
  27. cout << v[i].number << " " << v[i].total << endl;
  28. }
  29. return 0;
  30. }