#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const int MAX_NUM = 5; const int DIFFICULTY = 100000; int main() { int n, m; cin >> n >> m; vector x(n); vector > va(DIFFICULTY+2), vb(DIFFICULTY+2); for(int i=0; i> x[i] >> a >> b; va[a].push_back(i); vb[b].push_back(i); } vector cnt(MAX_NUM+1, 0); for(int i=0; i0; --i) cnt[i-1] += cnt[i]; int a = 0; int ans = INT_MAX; for(int b=DIFFICULTY+1; b>=0; --b){ for(int i : vb[b]){ ++ x[i]; ++ cnt[x[i]]; } while(cnt[2] >= m){ ans = min(ans, cnt[3]); if(a > DIFFICULTY) break; for(int i : va[a]){ -- cnt[x[i]]; -- x[i]; } ++ a; } } cout << ans << endl; return 0; }