diff --git a/Luogu/problem/P5763/P5763.cpp b/Luogu/problem/P5763/P5763.cpp new file mode 100644 index 00000000..6c9e64e4 --- /dev/null +++ b/Luogu/problem/P5763/P5763.cpp @@ -0,0 +1,88 @@ +#include + +using namespace std; + +struct node { + int t, m, p, s; + + bool operator<(const node& x) const { + return s < x.s; + } +}; + +int n, t, m, p, w = 0x3f3f3f3f, ans, cnt; +queue wait; +vector mem; +node x; + +bool assign(int t) { + if (mem.empty() || mem[0].s >= x.m) { + x.s = 0; + x.t = t; + mem.push_back(x); + sort(mem.begin(), mem.end()); + return true; + } + for (int i = 1; i < mem.size(); i++) { + if (mem[i].s - (mem[i - 1].s + mem[i - 1].m) >= x.m) { + x.s = mem[i - 1].s + mem[i - 1].m; + x.t = t; + mem.push_back(x); + sort(mem.begin(), mem.end()); + return true; + } + } + if (n - ((--mem.end())->s + (--mem.end())->m) >= x.m) { + x.s = (--mem.end())->s + (--mem.end())->m; + x.t = t; + mem.push_back(x); + sort(mem.begin(), mem.end()); + return true; + } + return false; +} + +void release() { + int nw = 0x3f3f3f3f; + for (int i = 0; i < mem.size(); i++) { + if (mem[i].t + mem[i].p == w) { + mem.erase(mem.begin() + i--); + } else { + nw = min(nw, mem[i].t + mem[i].p); + } + } + while (!wait.empty()) { + x = wait.front(); + if (assign(w)) { + nw = min(nw, wait.front().t + wait.front().p); + wait.pop(); + cnt++; + } else { + break; + } + } + w = nw; +} + +int main() { + cin >> n; + while (cin >> t >> m >> p, t || m || p) { + while (t >= w) release(); + x.t = t; + x.m = m; + x.p = p; + if (assign(t)) { + w = min(w, t + p); + } else { + wait.push(x); + } + } + while (!wait.empty()) release(); + ans = w; + for (int i = 0; i < mem.size(); i++) { + ans = max(ans, mem[i].t + mem[i].p); + } + cout << ans << endl + << cnt << endl; + return 0; +} diff --git a/Luogu/problem/P5763/data/P5763_1.in b/Luogu/problem/P5763/data/P5763_1.in new file mode 100644 index 00000000..ba041853 --- /dev/null +++ b/Luogu/problem/P5763/data/P5763_1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d19cdc0ae9f2b6f7df997e646c2f8f8af83370867fe494c302b1e812901c95e7 +size 53 diff --git a/Luogu/problem/P5763/data/P5763_1.out b/Luogu/problem/P5763/data/P5763_1.out new file mode 100644 index 00000000..965a7ed7 --- /dev/null +++ b/Luogu/problem/P5763/data/P5763_1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:670460a1596a0d424b48e10ddf0812c2adc74838d68dcb0f6f31a8ebd83b7c76 +size 6