#include <iostream>
#include <random>
#include <ctime>
#include <algorithm>
#include <queue>
using namespace std;
int rn( int s, int d )
{
static mt19937 rd( time( nullptr ) );
if( d <= s )
return s;
else
return rd() % ( d - s + 1 ) + s;
}
vector<pair< pair<int, int>, int > > v;
int main()
{
ios_base::sync_with_stdio( false );
cin.tie( nullptr );
int n, p;
cin >> n >> p;
for( int i = 0; i < n; ++i )
{
int s, d, t;
cin >> s >> d >> t;
v.emplace_back( make_pair(s, d), t );
}
sort( v.begin(), v.end() );
bool fail = false;
int cur = 1;
int concur = 1;
int max_concur = 1;
priority_queue<int> q;
q.push( v[0].first.second );
for( int i = 1; i < n; ++i )
{
if( v[i] == v[i-1] )
++cur;
else
cur = 1;
++concur;
q.push( v[i].first.second );
while( q.top() < v[i].first.first )
{
--concur;
q.pop();
}
max_concur = max( max_concur, concur );
if( cur > p )
fail = true;
}
if( fail || rn( 1, (max_concur-p+1) ) == 1 )
cout << "NIE";
else
cout << "TAK";
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | #include <iostream> #include <random> #include <ctime> #include <algorithm> #include <queue> using namespace std; int rn( int s, int d ) { static mt19937 rd( time( nullptr ) ); if( d <= s ) return s; else return rd() % ( d - s + 1 ) + s; } vector<pair< pair<int, int>, int > > v; int main() { ios_base::sync_with_stdio( false ); cin.tie( nullptr ); int n, p; cin >> n >> p; for( int i = 0; i < n; ++i ) { int s, d, t; cin >> s >> d >> t; v.emplace_back( make_pair(s, d), t ); } sort( v.begin(), v.end() ); bool fail = false; int cur = 1; int concur = 1; int max_concur = 1; priority_queue<int> q; q.push( v[0].first.second ); for( int i = 1; i < n; ++i ) { if( v[i] == v[i-1] ) ++cur; else cur = 1; ++concur; q.push( v[i].first.second ); while( q.top() < v[i].first.first ) { --concur; q.pop(); } max_concur = max( max_concur, concur ); if( cur > p ) fail = true; } if( fail || rn( 1, (max_concur-p+1) ) == 1 ) cout << "NIE"; else cout << "TAK"; return 0; } |
English