#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
map <int, pair<int, int> > roznice;
for (int i = 0; i < n; i++) {
int strona, wspolrzedna, czas;
cin >> strona >> wspolrzedna >> czas;
int roznica = wspolrzedna - czas;
if (strona == 1)
roznice[roznica].first++;
else roznice[roznica].second++;
}
int wynik = 0;
for (auto iter : roznice)
wynik += min(iter.second.first, iter.second.second);
cout << wynik;
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; map <int, pair<int, int> > roznice; for (int i = 0; i < n; i++) { int strona, wspolrzedna, czas; cin >> strona >> wspolrzedna >> czas; int roznica = wspolrzedna - czas; if (strona == 1) roznice[roznica].first++; else roznice[roznica].second++; } int wynik = 0; for (auto iter : roznice) wynik += min(iter.second.first, iter.second.second); cout << wynik; return 0; } |
English