Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using ll = long long;
- using namespace std;
- vector<int> tokenize(const string &s) {
- stringstream ss(s);
- string token;
- vector<int> tokens;
- while (getline(ss, token, ' ')) {
- //cerr << token << ' ';
- tokens.push_back(stoi(token));
- }
- return tokens;
- }
- signed main() {
- freopen("text.in", "r", stdin);
- freopen("text.txt", "w", stdout);
- ll n;
- cin >> n;
- string line;
- cin.get();
- int maxi = INT_MIN, maxiID, maxi2 = INT_MIN, maxi2ID;
- vector<vector<int>> matrix(n + 3);
- for (ll i = 1; i <= n; i++) {
- getline(cin, line);
- vector<int> curr = tokenize(line);
- matrix[i] = curr;
- int maxiFromCurr = *max_element(curr.begin() + 1, curr.end());
- if (maxi < maxiFromCurr) {
- maxi2 = maxi;
- maxi2ID = maxiID;
- maxi = maxiFromCurr;
- maxiID = i;
- } else if (maxi2 < maxiFromCurr) {
- maxi2 = maxiFromCurr;
- maxi2ID = i;
- }
- }
- for (int i = 1; i <= n; i++) {
- int maxiFromCurr = *max_element(matrix[i].begin() + 1, matrix[i].end());
- int miniFromCurr = *min_element(matrix[i].begin() + 1, matrix[i].end());
- if (miniFromCurr == maxi || miniFromCurr == maxi2) {
- cout << "NO TRADE" << endl;
- continue;
- }
- if (maxiFromCurr == maxi) {
- cout << i << ' ' << miniFromCurr << ' ' << (maxi2ID != i ? maxi2ID : maxiID) << ' ' << maxi2 << endl;
- maxi2ID = maxiID;
- continue;
- }
- cout << i << ' ' << miniFromCurr << ' ' << maxiID << ' ' << maxi << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement