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
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <iostream>
#include <map>
#include <unordered_map>
#include <vector>
#include <string>
#include <set>
#include <algorithm>

using namespace std;

struct Entry
{
	Entry(int _r, int _w, int _t): r(_r), w(_w), t(_t)
	{
	}
	~Entry() {};
	int id = 0;
	int r, w, t = 0;
	int collisions = 0;
};

bool IsColiding(const Entry& a, const Entry& b)
{
	if (a.r == b.r)
	{
		if (a.w != b.w || a.t != a.t)
		{
			return false;
		}
		else
		{
			return true;
		}
	}

	int t1 = a.t + b.w;
	int t2 = b.t + a.w;

	if (t1 == t2)
	{
		return true;
	}

	return false;
}


int main()
{
	unsigned int N; 
	cin >> N;

	vector<Entry> dane;
	dane.reserve(N);

	vector <set<int>> kolizje;

	for (unsigned int i = 1; i <= N; ++i)
	{
		int r, w, t = 0;
		cin >> r >> w >> t;
		Entry entry(r, w, t);
		entry.id = i;

		for (int j = 0; j < dane.size(); ++j)
		{
			if (IsColiding(entry, dane[j]))
			{
				dane[j].collisions++;

				set<int> se = { entry.id, dane[j].id };
				kolizje.emplace_back(move(se));
			}
		}

		dane.emplace_back(move(entry));
	}


	sort(dane.begin(), dane.end(), [](const Entry& a, const Entry& b)
	{
		if (a.collisions < b.collisions)
		{
			return true;
		}

		return false;
	});

	unsigned int deletions = 0;

	while (kolizje.size() != 0)
	{
		auto& entry = dane.back();

		kolizje.erase(remove_if(kolizje.begin(), kolizje.end(), [&entry](const set<int>& se)
		{
			auto res = se.find(entry.id);

			if (res != se.end())
			{
				return true;
			}
			return false;

		}), kolizje.end());

	
		dane.pop_back();
		deletions++;
	}

	cout << deletions;
	return 0;
}