Advertisement
Aimannnhakim

Untitled

Apr 21st, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <bits.h>
  3. #include <vector>
  4. #include <bits/stdc++.h>
  5. using namespace std;
  6. void print(vector<int> n)
  7. {
  8. for (int x = 0; x < n.size(); x++)
  9. cout << n[x] << " ";
  10. cout << endl;
  11. }
  12.  
  13. int max(int& l, int& w, int x, int y)
  14. {
  15. if (x >= y) {
  16. l = x;
  17. w = y;
  18. }
  19. else {
  20. l = y;
  21. w = x;
  22. }
  23. }
  24.  
  25. void swap(pair<int, pair<int, int> >& xp, pair<int, pair<int, int> >& yp)
  26. {
  27. pair<int, pair<int, int> > temp = xp;
  28. xp = yp;
  29. yp = temp;
  30. }
  31.  
  32. // A function to implement bubble sort
  33. void bubbleSort(vector<pair<int, pair<int, int> > >& arr, int n)
  34. {
  35. int i, j;
  36. for (i = 0; i < n - 1; i++)
  37.  
  38. // Last i elements are already in place
  39. for (j = 0; j < n - i - 1; j++)
  40. if (arr[j].first * arr[j].second.first < arr[j + 1].first * arr[j + 1].second.first)
  41. swap(arr[j], arr[j + 1]);
  42. }
  43.  
  44. int main()
  45. {
  46.  
  47. vector<pair<int, pair<int, int> > > permuted;
  48. vector<pair<int, pair<int, int> > > inputnumber;
  49. int num;
  50. cin >> num;
  51. for (int a = 0; a < num; a++) {
  52. int i, j, k;
  53. cin >> i >> j >> k;
  54.  
  55. int l, w;
  56.  
  57. max(l, w, i, j);
  58. permuted.push_back(make_pair(l, make_pair(w, k)));
  59. max(l, w, k, j);
  60. permuted.push_back(make_pair(l, make_pair(w, i)));
  61. max(l, w, k, i);
  62. permuted.push_back(make_pair(l, make_pair(w, j)));
  63. }
  64. bubbleSort(permuted, permuted.size());
  65. vector<int> result;
  66. vector<int> max;
  67.  
  68. for (int x = 0; x < permuted.size(); x++) {
  69. max.push_back(permuted[x].second.second);
  70. result.push_back(x);
  71. }
  72. cout << endl;
  73. for (int x = 0; x < permuted.size(); x++) {
  74. cout << permuted[x].first << " " << permuted[x].second.first << " " << permuted[x].second.second << endl;
  75. }
  76.  
  77. int j = 0;
  78. int i = 1;
  79.  
  80. while (j != result.size() - 1) {
  81.  
  82. if (permuted[i].first < permuted[j].first && permuted[i].second.first < permuted[j].second.first) {
  83.  
  84. print(max);
  85.  
  86. if (max[j] + permuted[i].second.second > max[i]) {
  87. result[i] = j;
  88. max[i] = max[j] + permuted[i].second.second;
  89. print(max);
  90. }
  91. j++;
  92. while (j < i) {
  93. if (permuted[i].first < permuted[j].first && permuted[i].second.first < permuted[j].second.first) {
  94.  
  95. if (max[j] + permuted[i].second.second > max[i]) {
  96. result[i] = j;
  97. max[i] = max[j] + permuted[i].second.second;
  98. print(max);
  99. }
  100. }
  101. j++;
  102. }
  103. }
  104. i++;
  105. if (j != result.size() - 1)
  106. j = 0;
  107. }
  108. cout << max[result.size() - 1];
  109.  
  110. return 0;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement