Advertisement
STANAANDREY

ccc sch 2

Nov 5th, 2021
752
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using ll = long long;
  3. using namespace std;
  4.  
  5. vector<int> tokenize(const string &s) {
  6.     stringstream ss(s);
  7.     string token;
  8.     vector<int> tokens;
  9.     while (getline(ss, token, ' ')) {
  10.         //cerr << token << ' ';
  11.         tokens.push_back(stoi(token));
  12.     }
  13.     return tokens;
  14. }
  15.  
  16. signed main() {
  17.     freopen("text.in", "r", stdin);
  18.     freopen("text.txt", "w", stdout);
  19.     ll n;
  20.     cin >> n;
  21.     string line;
  22.     cin.get();
  23.     int maxi = INT_MIN, maxiID, maxi2 = INT_MIN, maxi2ID;
  24.     vector<vector<int>> matrix(n + 3);
  25.     for (ll i = 1; i <= n; i++) {
  26.         getline(cin, line);
  27.         vector<int> curr = tokenize(line);
  28.         matrix[i] = curr;
  29.         int maxiFromCurr = *max_element(curr.begin() + 1, curr.end());
  30.  
  31.         if (maxi < maxiFromCurr) {
  32.             maxi2 = maxi;
  33.             maxi2ID = maxiID;
  34.             maxi = maxiFromCurr;
  35.             maxiID = i;
  36.         } else if (maxi2 < maxiFromCurr) {
  37.             maxi2 = maxiFromCurr;
  38.             maxi2ID = i;
  39.         }
  40.     }
  41.     for (int i = 1; i <= n; i++) {
  42.         int maxiFromCurr = *max_element(matrix[i].begin() + 1, matrix[i].end());
  43.         int miniFromCurr = *min_element(matrix[i].begin() + 1, matrix[i].end());
  44.         if (miniFromCurr == maxi || miniFromCurr == maxi2) {
  45.             cout << "NO TRADE" << endl;
  46.             continue;
  47.         }
  48.         if (maxiFromCurr == maxi) {
  49.             cout << i << ' ' << miniFromCurr << ' ' << (maxi2ID != i ? maxi2ID : maxiID) << ' ' << maxi2 << endl;
  50.             maxi2ID = maxiID;
  51.             continue;
  52.         }
  53.         cout << i << ' ' << miniFromCurr << ' ' << maxiID << ' ' << maxi << endl;
  54.     }
  55.     return 0;
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement