#include<bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
using namespace std;
int n, a, b, c, l;
unordered_map<int, int> M1, M2;
int main()
{
scanf("%d", &n);
for(int i=0; i<n; i++)
{
scanf("%d%d%d", &a, &b, &c);
if(a==1)
{
M1[b-c]++;
}
else
{
M2[b-c]++;
}
}
for(auto I : M1)
{
l+=min(I.ss, M2[I.ff]);
}
printf("%d", l);
}
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 | #include<bits/stdc++.h> #define pb push_back #define ff first #define ss second #define mp make_pair using namespace std; int n, a, b, c, l; unordered_map<int, int> M1, M2; int main() { scanf("%d", &n); for(int i=0; i<n; i++) { scanf("%d%d%d", &a, &b, &c); if(a==1) { M1[b-c]++; } else { M2[b-c]++; } } for(auto I : M1) { l+=min(I.ss, M2[I.ff]); } printf("%d", l); } |
English