#include <bits/stdc++.h> using namespace std; #define pb push_back #define eb emplace_back #define mp make_pair #define lb lower_bound #define ub upper_bound #define f first #define s second #define sz(x) (x).size() #define all(x) (x).begin(), (x).end() using ll = long long; using pi = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vll = vector<ll>; using vs = vector<string>; using vpi = vector<pi>; using vpll = vector<pll>; map<int, int> m1; map<int, int> m2; int n, a, b, c; int main() { ios_base::sync_with_stdio(0); cin.tie(); cin >> n; for (int i = 1; i <= n; i++) { cin >> a >> b >> c; a--; if (a) m2[b - c]++; else m1[b - c]++; } int wyn = 0; for (auto i : m1) { // cout << i.f << endl; if (m2.count(i.f) > 0); wyn += min(m2[i.f], m1[i.f]); } cout << wyn; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #include <bits/stdc++.h> using namespace std; #define pb push_back #define eb emplace_back #define mp make_pair #define lb lower_bound #define ub upper_bound #define f first #define s second #define sz(x) (x).size() #define all(x) (x).begin(), (x).end() using ll = long long; using pi = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vll = vector<ll>; using vs = vector<string>; using vpi = vector<pi>; using vpll = vector<pll>; map<int, int> m1; map<int, int> m2; int n, a, b, c; int main() { ios_base::sync_with_stdio(0); cin.tie(); cin >> n; for (int i = 1; i <= n; i++) { cin >> a >> b >> c; a--; if (a) m2[b - c]++; else m1[b - c]++; } int wyn = 0; for (auto i : m1) { // cout << i.f << endl; if (m2.count(i.f) > 0); wyn += min(m2[i.f], m1[i.f]); } cout << wyn; } |