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 <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int maximumn=50000;
int h[maximumn];
int pozycjaa[maximumn];
int pozycjab[maximumn];

struct samochod
{
int h;
int pozycjaa;
int pozycjab;
};

samochod tauto[maximumn];
bool orderw(int a,int b) {return tauto[a].h<tauto[b].h;}
bool order1(int a,int b) {return tauto[a].pozycjaa<tauto[b].pozycjaa;}
bool order2(int a,int b) {return tauto[a].pozycjab<tauto[b].pozycjab;}
int main () {
int t,n,w;
int sam,samt;
int x1,y1,x2,y2;

bool wynik=true;
scanf("%d ",&t);
while(t--)
{
wynik=true;
scanf("%d %d",&n,&w);
for (int i=0;i<n;i++)
{
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);

tauto[i].h=y2-y1;
tauto[i].pozycjaa=x1;
h[i]=pozycjaa[i]=pozycjab[i]=i;
}
for (int i=0;i<n;i++)
{
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
tauto[i].pozycjab=x1;
}

sort(pozycjaa,pozycjaa+n,order1);
sort(pozycjab,pozycjab+n,order2);
for (int i=0;i<n;i++) {tauto[pozycjaa[i]].pozycjaa=i;tauto[pozycjab[i]].pozycjab=i;}
 
for (int i=0;i<n&&wynik;i++)
{
sam=pozycjaa[i];
if (tauto[sam].pozycjab<tauto[sam].pozycjaa)

for (int k=0;k<tauto[sam].pozycjaa&&wynik;k++)
{
samt=pozycjaa[k];
if(w-tauto[sam].h<tauto[samt].h && tauto[samt].pozycjab>tauto[sam].pozycjab) wynik=false;
}
}
if (wynik)printf("TAK\n");else printf("NIE\n");
}
return 0;
}