QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#129145 | #3998. The Profiteer | nhuang685 | WA | 1ms | 3548kb | C++20 | 3.9kb | 2023-07-21 23:44:45 | 2023-07-21 23:44:47 |
Judging History
answer
/**
* @file qoj3998F1.cpp
* @author n685
* @brief
* @date 2023-07-19
*
*
*/
#include <bits/stdc++.h>
#ifdef LOCAL
std::ifstream cin;
std::ofstream cout;
using std::cerr;
#else
using std::cin;
using std::cout;
#define cerr \
if (false) \
std::cerr
#endif
namespace K {
int64_t mx;
std::vector<std::vector<int64_t>> val;
void rollback(int a) { val.resize((int)val.size() - a); }
void add(int64_t v, int64_t c) {
val.push_back(std::vector<int64_t>(mx + 2));
auto &pre = val.end()[-2], &cur = val.back();
int64_t ans = 0;
for (int64_t i = 0; i <= mx; ++i) {
cur[i] = pre[i];
if (i >= c)
cur[i] = std::max(cur[i], pre[i - c] + v);
ans += cur[i];
}
cur.back() = ans;
}
int64_t sum() { return val.empty() ? 0 : val.back().back(); }
}; // namespace K
int main() {
#ifdef LOCAL
cin.open("input.txt");
cout.rdbuf()->pubsetbuf(0, 0);
cout.open("output.txt");
#else
cin.tie(nullptr)->sync_with_stdio(false);
#endif
int n;
int64_t k, E;
cin >> n >> k >> E;
K::mx = k;
K::val.push_back(std::vector<int64_t>(k + 2));
E *= k;
std::vector<int64_t> v(n), a(n), b(n);
for (int i = 0; i < n; ++i)
cin >> v[i] >> a[i] >> b[i];
int64_t ans = 0;
auto dnq = [&](auto &self, int l, int r, int dl, int dr) {
if (dl == dr) {
if (dl == n - 1) {
int dm = dl;
int ll = l, rr = std::min(r, dm);
for (int i = dm + 1; i <= r; ++i)
K::add(v[i], a[i]);
while (ll < rr) {
int mid = (ll + rr + 1) / 2;
// add from mid to rr
for (int i = ll; i < mid; ++i)
K::add(v[i], a[i]);
for (int i = mid; i <= rr; ++i)
K::add(v[i], b[i]);
if (K::sum() <= E) {
K::rollback(rr - mid + 1);
ll = mid;
} else {
K::rollback(rr - ll + 1);
for (int i = mid; i <= rr; ++i)
K::add(v[i], b[i]);
rr = mid - 1;
}
}
bool g = K::sum() <= E;
if (g)
ans += (int64_t)(ll - l + 1) * (n - dl);
} else
ans += (int64_t)(r - l + 1) * (n - dl);
return;
}
int dm = (dl + dr) / 2;
for (int i = std::max(r + 1, dl); i <= dr; ++i) {
if (i > dm)
K::add(v[i], a[i]);
else
K::add(v[i], b[i]);
}
int ll = l, rr = std::min(r, dm);
for (int i = dm + 1; i <= r; ++i)
K::add(v[i], a[i]);
while (ll < rr) {
int mid = (ll + rr + 1) / 2;
// add from mid to rr
for (int i = ll; i < mid; ++i)
K::add(v[i], a[i]);
for (int i = mid; i <= rr; ++i)
K::add(v[i], b[i]);
if (K::sum() <= E) {
K::rollback(rr - mid + 1);
ll = mid;
} else {
K::rollback(rr - ll + 1);
for (int i = mid; i <= rr; ++i)
K::add(v[i], b[i]);
rr = mid - 1;
}
}
int m = ll;
K::add(v[m], b[m]);
bool g = (K::sum() <= E);
// added all but m
K::rollback(r - l + dr - std::max(r + 1, dl) + 2);
if (!g)
m = l - 1;
if (g) {
for (int i = m + 1; i < dl; ++i)
K::add(v[i], b[i]);
for (int i = dm + 1; i <= dr; ++i)
K::add(v[i], a[i]);
self(self, l, m, dl, dm);
K::rollback(std::min(dl - 1, r) - m + dr - dm);
}
if (m + 1 <= r) {
for (int i = l; i <= std::min(dl - 1, m); ++i)
K::add(v[i], a[i]);
for (int i = std::max(r + 1, dl); i <= dm; ++i)
K::add(v[i], b[i]);
self(self, m + 1, r, dm + 1, dr);
K::rollback(dm - std::max(r + 1, dl) + std::min(dl - 1, m) - l + 2);
}
};
dnq(dnq, 0, n - 1, 0, n - 1);
cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3548kb
input:
4 5 3 3 2 4 1 2 3 2 1 2 3 1 3
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3524kb
input:
4 5 4 3 2 4 1 2 3 2 1 2 3 1 3
output:
3
result:
ok single line: '3'
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 3460kb
input:
4 5 5 3 2 4 1 2 3 2 1 2 3 1 3
output:
4
result:
wrong answer 1st lines differ - expected: '7', found: '4'