fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. vector <pair <pair <int, int>, int> > el;
  4. vector <pair <int, int> > newel;
  5. int memo[5000];
  6. int main(){
  7. int sz;
  8. int iq;
  9. int cont = 0;
  10. while(cin >> sz >> iq){
  11. el.push_back(make_pair(make_pair(sz,iq),cont));
  12. cont++;
  13. }
  14. sort(el.begin(), el.end());
  15. int aux = el[0].first.second;
  16. int auxp = el[0].second;
  17. for(int i=1; i<el.size(); i++){
  18. if(el[i].first.first == el[i-1].first.first){
  19. if(el[i].first.second > aux){
  20. aux = el[i].first.second;
  21. auxp = el[i].second;
  22. }
  23. }
  24. else{
  25. newel.push_back(make_pair(aux, auxp));
  26. aux = el[i].first.second;
  27. auxp = el[i].second;
  28. }
  29. }
  30. for(int i=0; i<newel.size(); i++){
  31. cout << newel[i].first << " " << newel[i].second << endl;
  32. }
  33. //vector < vector <int> > ans(newel.size());
  34. //ans[0].push_back(newel[0].second);
  35. /*for(int i=1; i<newel.size(); i++){
  36.   for(int j=0; j<i; j++){
  37.   if((newel[i].first < newel[j].first) && (ans[i].size() < ans[j].size()+1)) ans[i] = ans[j];
  38.   }
  39.   ans[i].push_back(newel[i].second);
  40.   }*/
  41. /*int maxi = ans[0].size();
  42.   int auxp2 = 0;
  43.   for(int i=0; i<ans.size(); i++){
  44.   if(maxi < ans[i].size()){
  45.   maxi = ans[i].size();
  46.   auxp2 = i;
  47.   }
  48.   cout << ans[i].size() << endl;
  49.   }*/
  50. //cout << maxi << '\n';
  51. /*for(int i=0; i<ans[auxp2].size(); i++){
  52.   cout << ans[auxp2][i] << '\n';
  53.   }*/
  54. return 0;
  55. }
  56.  
Success #stdin #stdout 0s 15256KB
stdin
1 1
1 2
1 9998
1 9999
1 10000
2 1
2 2
2 9998
2 9999
2 10000
9998 1
9998 2
9998 9998
9998 9999
9998 10000
9999 1
9999 2
9999 9998
9999 9999
9999 10000
10000 1
10000 2
10000 9998
10000 9999
10000 10000
1 1
2 1
9998 1
9999 1
10000 1
1 2
2 2
9998 2
9999 2
10000 2
1 9998
2 9998
9998 9998
9999 9998
10000 9998
1 9999
2 9999
9998 9999
9999 9999
10000 9999
1 10000
2 10000
9998 10000
9999 10000
10000 10000
stdout
10000 4
10000 9
10000 14
10000 19