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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
| #include <bits/stdc++.h>
using namespace std;
#define MAXN 620
int maps[MAXN][MAXN]; int pre[MAXN]; int level[MAXN]; int gap[MAXN];
int SAP(int vs, int vt) { memset(pre, -1, sizeof(pre)); memset(level, 0, sizeof(level)); memset(gap, 0, sizeof(gap)); gap[0] = vt; int v, u = pre[vs] = vs, maxflow = 0, aug = INT_MAX; while (level[vs] < vt) { for (v = 1; v <= vt; v++) { if (maps[u][v] > 0 && level[u] == level[v] + 1) { break; } } if (v <= vt) { pre[v] = u; u = v; if (v == vt) { aug = INT_MAX; for (int i = v; i != vs; i = pre[i]) { if (aug > maps[pre[i]][i]) { aug = maps[pre[i]][i]; } } maxflow += aug; for (int i = v; i != vs; i = pre[i]) { maps[pre[i]][i] -= aug; maps[i][pre[i]] += aug; } u = vs; } } else { int minlevel = vt; for (v = 1; v <= vt; v++) { if (maps[u][v] > 0 && minlevel > level[v]) { minlevel = level[v]; } } gap[level[u]]--; if (gap[level[u]] == 0) break; level[u] = minlevel + 1; gap[level[u]]++; u = pre[u]; } } return maxflow; }
int n, m; const int MaxPeople = 210; const int Ed = 615; struct costman { int b, e, need, time; }; set<int> timelist; costman costmanlist[MaxPeople];
void init() { memset(maps, 0, sizeof(maps)); set<int>::iterator iterl = timelist.begin(); set<int>::iterator iterr = timelist.begin(); iterr++; int curiter = 0; for (size_t i = 0; i < n; i++) { maps[0][i + 1] = costmanlist[i].need * costmanlist[i].time; } while (iterr != timelist.end()) { maps[205 + curiter][Ed] = ((*iterr) - (*iterl)) * m; for (size_t i = 0; i < n; i++) { if (costmanlist[i].b <= *iterl && costmanlist[i].e >= *iterr) { maps[i + 1][curiter + 205] = INT_MAX; } } iterl++; iterr++; curiter++; } }
int main() { #ifdef ACM_LOCAL freopen("./in.txt", "r", stdin); freopen("./out.txt", "w", stdout); #endif ios::sync_with_stdio(false); while (cin >> n >> m) { timelist.clear(); long long sum = 0; for (size_t i = 0; i < n; i++) { cin >> costmanlist[i].b >> costmanlist[i].need >> costmanlist[i].e >> costmanlist[i].time; sum += costmanlist[i].need * costmanlist[i].time; timelist.insert(costmanlist[i].b); timelist.insert(costmanlist[i].e); } init(); cout << (sum == SAP(0, Ed) ? "Yes" : "No") << endl; } return 0; }
|