#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
using namespace std;
struct car{
int nr;
int x;
int h;
};
bool compare(const car& p,const car& q){
return p.x < q.x;
}
vector < car > jest, plan;
int t, n, w;
int a, b, c, d;
car temp;
bool czy=1;
int main()
{
scanf("%d", &t);
for(int z=0;z<t;z++)
{
czy=1;
jest.clear();
plan.clear();
scanf("%d %d", &n, &w);
for(int x=1;x<=n;x++)
{
scanf("%d %d %d %d", &temp.x, &a, &c, &b);
temp.h=abs(a-b);
temp.nr=x;
jest.push_back(temp);
}
for(int v=1;v<=n;v++)
{
scanf("%d %d %d %d", &temp.x, &a, &b, &c);
temp.nr=v;
temp.h=jest[v-1].h;
plan.push_back(temp);
}
sort(jest.begin(), jest.end(), compare);
sort(plan.begin(), plan.end(), compare);
for(int s=0;s<n;s++)
{
for(int f=0; f<n; f++)
{
if(plan[s].nr == jest[f].nr)
{
jest[f].h=0;
f=n+1;
}
else
{
if(w-jest[f].h < plan[s].h)
{
czy=0;
f=n+1;
s=n+1;
}
}
}
}
if(czy==1)
printf("TAK\n");
else
printf("NIE\n");
}
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 65 66 67 68 69 70 71 72 73 74 75 76 77 | #include <iostream> #include <algorithm> #include <cstdio> #include <vector> #include <cmath> using namespace std; struct car{ int nr; int x; int h; }; bool compare(const car& p,const car& q){ return p.x < q.x; } vector < car > jest, plan; int t, n, w; int a, b, c, d; car temp; bool czy=1; int main() { scanf("%d", &t); for(int z=0;z<t;z++) { czy=1; jest.clear(); plan.clear(); scanf("%d %d", &n, &w); for(int x=1;x<=n;x++) { scanf("%d %d %d %d", &temp.x, &a, &c, &b); temp.h=abs(a-b); temp.nr=x; jest.push_back(temp); } for(int v=1;v<=n;v++) { scanf("%d %d %d %d", &temp.x, &a, &b, &c); temp.nr=v; temp.h=jest[v-1].h; plan.push_back(temp); } sort(jest.begin(), jest.end(), compare); sort(plan.begin(), plan.end(), compare); for(int s=0;s<n;s++) { for(int f=0; f<n; f++) { if(plan[s].nr == jest[f].nr) { jest[f].h=0; f=n+1; } else { if(w-jest[f].h < plan[s].h) { czy=0; f=n+1; s=n+1; } } } } if(czy==1) printf("TAK\n"); else printf("NIE\n"); } return 0; } |
English