#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
typedef vector<int> vi;
#define pb push_back
#define sz size()
typedef pair<int,int> pii;
#define mp make_pair
#define st first
#define nd second
typedef long long ll;
#define INF 1000000001
#define ALL(t) t.begin(),t.end()
#define SC(a) scanf("%d", &a)
#define GET(a) int a; SC(a)
#define ISDEBUG 1
#define dprintf(...) if(ISDEBUG) \
{printf("\033[31m"); printf(__VA_ARGS__); printf("\033[0m");}
template <class It> void dptab(It b, It e, const char* f="%d ") {
if(ISDEBUG) {
for(It it=b; it!=e; ++it) dprintf(f, *it); dprintf("\n");
}}
int main() {
map<int, int> occurrences[2];
GET(n);
FOR(i,0,n) {
GET(type);
GET(x);
GET(tx);
--type;
int id = x-tx;
if(!occurrences[type].count(id)) {
occurrences[type][id] = 0;
}
occurrences[type][id]++;
}
int to_be_deleted = 0;
for(const auto& id_counter : occurrences[0]) {
const int& id = id_counter.first;
const int& count = id_counter.second;
if(occurrences[1].count(id)) {
to_be_deleted += min(count, occurrences[1][id]);
}
}
printf("%d\n", to_be_deleted);
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 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 FOR(i,a,b) for(int i=(a); i<(b); ++i) typedef vector<int> vi; #define pb push_back #define sz size() typedef pair<int,int> pii; #define mp make_pair #define st first #define nd second typedef long long ll; #define INF 1000000001 #define ALL(t) t.begin(),t.end() #define SC(a) scanf("%d", &a) #define GET(a) int a; SC(a) #define ISDEBUG 1 #define dprintf(...) if(ISDEBUG) \ {printf("\033[31m"); printf(__VA_ARGS__); printf("\033[0m");} template <class It> void dptab(It b, It e, const char* f="%d ") { if(ISDEBUG) { for(It it=b; it!=e; ++it) dprintf(f, *it); dprintf("\n"); }} int main() { map<int, int> occurrences[2]; GET(n); FOR(i,0,n) { GET(type); GET(x); GET(tx); --type; int id = x-tx; if(!occurrences[type].count(id)) { occurrences[type][id] = 0; } occurrences[type][id]++; } int to_be_deleted = 0; for(const auto& id_counter : occurrences[0]) { const int& id = id_counter.first; const int& count = id_counter.second; if(occurrences[1].count(id)) { to_be_deleted += min(count, occurrences[1][id]); } } printf("%d\n", to_be_deleted); return 0; } |
English