fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int n, m;
  8. cin >> n >> m;
  9. vector<vector<string>> input(n);
  10. for(int i = 0; i < n; i++) {
  11. string name;
  12. int region, score;
  13. cin >> name >> region >>score;
  14. vector<string> v{name, to_string(region), to_string(score)};
  15. input[i] = v;
  16. }
  17. sort(input.begin(), input.end(), [&](vector<string>& a, vector<string>& b) {
  18. if(a[1] == b[1]) return a[2] > b[2];
  19. return a[1] < b[1];
  20. });
  21. int regionCnt = 0;
  22. for(int i = 0; i < n; i += regionCnt){
  23. string firstCan = "", secondCan = "";
  24. int ans1 = -1, ans2 = -1, ans3 = -1, currRegion = stoi(input[i][1]);
  25. regionCnt = 0;
  26. for(int j = 0; i+j < n && stoi(input[i+j][1]) == currRegion; j++) {
  27. regionCnt++;
  28. if(stoi(input[i+j][2]) > ans1) {
  29. ans1 = stoi(input[i+j][2]);
  30. firstCan = input[i+j][0];
  31. }
  32. else if(stoi(input[i+j][2]) > ans2) {
  33. ans2 = stoi(input[i+j][2]);
  34. secondCan = input[i+j][0];
  35. } else if(stoi(input[i+j][2]) > ans3)
  36. ans3 = stoi(input[i+j][2]);
  37. }
  38. if(ans2 == ans3) cout << "?" << endl;
  39. else cout << firstCan << " " << secondCan << endl;
  40. }
  41. return 0;
  42. }
Success #stdin #stdout 0.01s 5408KB
stdin
Standard input is empty
stdout
?