Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <bits.h>
- #include <vector>
- #include <bits/stdc++.h>
- using namespace std;
- void print(vector<int> n)
- {
- for (int x = 0; x < n.size(); x++)
- cout << n[x] << " ";
- cout << endl;
- }
- int max(int& l, int& w, int x, int y)
- {
- if (x >= y) {
- l = x;
- w = y;
- }
- else {
- l = y;
- w = x;
- }
- }
- void swap(pair<int, pair<int, int> >& xp, pair<int, pair<int, int> >& yp)
- {
- pair<int, pair<int, int> > temp = xp;
- xp = yp;
- yp = temp;
- }
- // A function to implement bubble sort
- void bubbleSort(vector<pair<int, pair<int, int> > >& arr, int n)
- {
- int i, j;
- for (i = 0; i < n - 1; i++)
- // Last i elements are already in place
- for (j = 0; j < n - i - 1; j++)
- if (arr[j].first * arr[j].second.first < arr[j + 1].first * arr[j + 1].second.first)
- swap(arr[j], arr[j + 1]);
- }
- int main()
- {
- vector<pair<int, pair<int, int> > > permuted;
- vector<pair<int, pair<int, int> > > inputnumber;
- int num;
- cin >> num;
- for (int a = 0; a < num; a++) {
- int i, j, k;
- cin >> i >> j >> k;
- int l, w;
- max(l, w, i, j);
- permuted.push_back(make_pair(l, make_pair(w, k)));
- max(l, w, k, j);
- permuted.push_back(make_pair(l, make_pair(w, i)));
- max(l, w, k, i);
- permuted.push_back(make_pair(l, make_pair(w, j)));
- }
- bubbleSort(permuted, permuted.size());
- vector<int> result;
- vector<int> max;
- for (int x = 0; x < permuted.size(); x++) {
- max.push_back(permuted[x].second.second);
- result.push_back(x);
- }
- cout << endl;
- for (int x = 0; x < permuted.size(); x++) {
- cout << permuted[x].first << " " << permuted[x].second.first << " " << permuted[x].second.second << endl;
- }
- int j = 0;
- int i = 1;
- while (j != result.size() - 1) {
- if (permuted[i].first < permuted[j].first && permuted[i].second.first < permuted[j].second.first) {
- print(max);
- if (max[j] + permuted[i].second.second > max[i]) {
- result[i] = j;
- max[i] = max[j] + permuted[i].second.second;
- print(max);
- }
- j++;
- while (j < i) {
- if (permuted[i].first < permuted[j].first && permuted[i].second.first < permuted[j].second.first) {
- if (max[j] + permuted[i].second.second > max[i]) {
- result[i] = j;
- max[i] = max[j] + permuted[i].second.second;
- print(max);
- }
- }
- j++;
- }
- }
- i++;
- if (j != result.size() - 1)
- j = 0;
- }
- cout << max[result.size() - 1];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement