# kebab HDU - 2883（思维建图，最大流）

#pragma GCC optimize(2)
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<cstring>
#include<iostream>
#define _PI acos(-1.0)
#define esp 1e-9
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define FRE freopen("abc.in", "r", stdin)
#define mEm(X,Y) memset(X,Y,sizeof(X))
#define pb(a) push_back(a)
#define pa(a) pop_back(a)
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rep1(i,a,b) for(int i=a;i<=b;++i)
#define INF 0x3f3f3f3f
typedef long long LL;
typedef unsigned long long ULL;
LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
void exgcd(LL a, LL b, LL& x, LL& y) {
if (!b) {
x = 1, y = 0;
return;
}
exgcd(a, b, y, x);
y -= a / b * x;
}
using namespace std;
/*===========================================*/
//使用非vector链式前向星
class MAXFLOW
{
public:
static const int MAXN = 100200;

struct Edge
{
int v, flow, next;
} e[MAXN << 2];

int head[MAXN], edge_num, layer[MAXN], start, end;

{
edge_num = 0;
}

void addedge(int u, int v, int w)
{
e[edge_num].v = v;
e[edge_num].flow = w;
e[edge_num].v = u;
e[edge_num].flow = 0;
}

bool bfs()
{
queue<int> Q;
Q.push(start);
memset(layer, 0, sizeof(layer));
layer[start] = 1;
while (Q.size())
{
int u = Q.front();
Q.pop();

if (u == end)
return true;

for (int j = head[u]; j != -1; j = e[j].next)
{
int v = e[j].v;
if (layer[v] == false && e[j].flow)
{
layer[v] = layer[u] + 1;
Q.push(v);
}
}
}

return false;
}
int dfs(int u, int MaxFlow, int End)
{
if (u == End)
return MaxFlow;

int uflow = 0;

for (int j = head[u]; j != -1; j = e[j].next)
{
int v = e[j].v;

if (layer[v] - 1 == layer[u] && e[j].flow)
{
int flow = min(MaxFlow - uflow, e[j].flow);
flow = dfs(v, flow, End);
e[j].flow -= flow;
e[j ^ 1].flow += flow;

uflow += flow;

if (uflow == MaxFlow)
break;
}
}
if (uflow == 0)
layer[u] = 0;
return uflow;
}
int dinic()
{
int MaxFlow = 0;

while (bfs())
MaxFlow += dfs(start, 0x3f3f3f3f, end);
return MaxFlow;
}
}sol;

vector<int> s, e;
vector<int> time;

int main()
{
int n, m;
while (~scanf("%d%d", &n, &m))
{
time.clear(), s.clear(), e.clear();
int a, b, c, d;
int tot = 0;
rep1(i, 1, n)
{
scanf("%d%d%d%d", &a, &b, &c, &d);
s.push_back(a), e.push_back(c), time.push_back(a), time.push_back(c);
tot += b * d;
}
sort(time.begin(), time.end());
time.erase(unique(time.begin(), time.end()), time.end());
sol.start = 0, sol.end = n + time.size();
rep(i, 1, time.size())
{
sol.addedge(n + i, sol.end, m * (time[i] - time[i - 1]));
rep(j, 0, n)
{
if (time[i - 1] >= s[j] && time[i] <= e[j])
sol.addedge(j + 1, n + i, INF);
}
}
printf("%s\n", sol.dinic() == tot ? "Yes" : "No");
}
}

10-22 24
07-08 129

07-11 99
08-16 853
06-28 657
08-17 447
07-13 255
08-18 444