QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#339026 | #3998. The Profiteer | Leasier | TL | 247ms | 8112kb | C++98 | 2.2kb | 2024-02-26 16:51:17 | 2024-02-26 16:51:17 |
Judging History
answer
#include <stdio.h>
#include <string.h>
typedef long long ll;
int v[200007], a[200007], b[200007], pos[200007], dp[10000007];
inline int max(int a, int b){
return a > b ? a : b;
}
inline void insert(int v, int w, int k){
for (register int i = k; i >= v; i--){
dp[i] = max(dp[i], dp[i - v] + w);
}
}
void solve(int l1, int r1, int l2, int r2, int k, ll limit){
if (l2 == r2){
for (register int i = l1; i <= r1; i++){
pos[i] = l2;
}
return;
}
int mid = (l1 + r1) >> 1, L = max(l2, mid), R = r2, llst = mid, rlst = r2, *save = new int[k + 1];
memcpy(save, dp, sizeof(int) * (k + 1));
for (register int i = l1; i < mid; i++){
insert(a[i], v[i], k);
}
pos[mid] = mid - 1;
while (L <= R){
int _mid = (L + R) >> 1, *_save = new int[k + 1];
ll sum = 0;
memcpy(_save, dp, sizeof(int) * (k + 1));
for (register int i = llst; i <= _mid; i++){
insert(b[i], v[i], k);
}
for (register int i = _mid + 1; i <= rlst; i++){
insert(a[i], v[i], k);
}
for (register int i = 1; i <= k; i++){
sum += dp[i];
}
if (sum <= limit){
R = _mid - 1;
memcpy(dp, _save, sizeof(int) * (k + 1));
for (register int i = _mid + 1; i <= rlst; i++){
insert(a[i], v[i], k);
}
rlst = _mid;
} else {
L = _mid + 1;
pos[mid] = _mid;
memcpy(dp, _save, sizeof(int) * (k + 1));
for (register int i = llst; i <= _mid; i++){
insert(b[i], v[i], k);
}
llst = _mid + 1;
}
delete _save;
}
if (l1 < mid){
memcpy(dp, save, sizeof(int) * (k + 1));
for (register int i = pos[mid] + 1; i <= r2; i++){
insert(a[i], v[i], k);
}
solve(l1, mid - 1, l2, pos[mid], k, limit);
}
if (r1 > mid){
memcpy(dp, save, sizeof(int) * (k + 1));
for (register int i = l1; i <= mid; i++){
insert(a[i], v[i], k);
}
solve(mid + 1, r1, pos[mid], r2, k, limit);
}
memcpy(dp, save, sizeof(int) * (k + 1));
delete save;
}
int main(){
int n, k, e;
ll limit, ans = 0;
scanf("%d %d %d", &n, &k, &e);
limit = (ll)k * e;
for (register int i = 1; i <= n; i++){
scanf("%d %d %d", &v[i], &a[i], &b[i]);
}
solve(1, n, 0, n, k, limit);
for (register int i = 1; i <= n; i++){
ans += n - pos[i];
}
printf("%lld", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5944kb
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: 5916kb
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: 0
Accepted
time: 1ms
memory: 5872kb
input:
4 5 5 3 2 4 1 2 3 2 1 2 3 1 3
output:
7
result:
ok single line: '7'
Test #4:
score: 0
Accepted
time: 247ms
memory: 8112kb
input:
200000 50 23333 2620 5 21 8192 17 34 6713 38 46 6687 13 42 390 9 13 4192 7 37 7898 17 21 1471 16 45 3579 22 40 9628 8 23 7164 28 45 3669 14 31 5549 29 35 4670 30 39 5811 15 20 4162 18 29 7590 29 41 7786 23 35 383 9 40 5576 39 46 5586 4 9 1110 14 33 8568 4 6 8548 39 42 9133 10 42 6679 22 39 8353 33 3...
output:
0
result:
ok single line: '0'
Test #5:
score: -100
Time Limit Exceeded
input:
200000 50 233332 8019 18 20 3111 27 40 2015 16 47 6491 17 18 1224 30 38 428 23 34 7521 4 41 7252 6 33 4121 32 45 4230 18 35 1605 21 42 9489 17 25 3704 35 45 6202 8 22 6493 1 5 3041 14 46 4509 23 43 9646 11 48 5294 19 27 3562 19 40 9408 30 47 1751 21 29 4053 4 27 5596 32 49 8609 13 29 1686 4 31 3588 ...