#include using namespace std; const int oo = 0x3f3f3f3f; const double eps = 1e-9; const double PI = 2.0 * acos(0.0); typedef long long ll; typedef unsigned long long ull; typedef pair pii; typedef vector vi; typedef vector vs; #define sz(c) int((c).size()) #define all(c) (c).begin(), (c).end() #define FOR(i,a,b) for (int i = (a); i < (b); i++) #define FORS(i,a,b,s) for (int i = (a); i < (b); i=i+(s)) #define FORD(i,a,b) for (int i = int(b)-1; i >= (a); i--) #define FORIT(i,c) for (__typeof__((c).begin()) i = (c).begin(); i != (c).end(); i++) int s[3000]; int ep[3000]; int eu[3000]; int st[3000]; vector exSt; int dp[3000][3000]; int main(){ int n; cin >> n; map events; FOR(i,0,n){ cin >> s[i] >> ep[i] >> eu[i] >> st[i]; events[s[i]] = i; } int np = 0; // by default all exams are non-pass vector passed(n, false); vector impossible(n, false); int lastTaken = -1; FOR(i,0,2*n){ int lastTime = 0; int accumulated = 0; int cheapPass = 1000000; int cheapPassIdx = -1; int startToStudy = -1; bool aborted = false; for (auto [time, exam] : events){ int timeToStudy = time - lastTime + accumulated; if (passed[exam]){ if (timeToStudy < st[exam]){ impossible[lastTaken] = true; passed[lastTaken] = false; aborted = true; break; } accumulated = timeToStudy - st[exam]; lastTime = ep[exam]; } else { if (!impossible[exam] && timeToStudy >= st[exam]){ if (cheapPass > st[exam]){ cheapPass = st[exam]; cheapPassIdx = exam; } } // simulate further pretending we do not pass accumulated += time-lastTime; lastTime = eu[exam]; } } if (aborted){ lastTaken = -1; np--; continue; } if (cheapPassIdx == -1) break; passed[cheapPassIdx] = true; lastTaken = cheapPassIdx; np++; } cout << np << endl; }