#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 302020
typedef long long ll;
typedef pair<int, int> pii;
ll tdp[MAX]; // full dp
ll bdp[MAX]; // zero dp
ll sum[MAX];
vector<pii> locs[MAX];
struct bit {
int N;
bool rev;
vector<ll> tree;
bit(int N, bool rev) :N(N + 2), rev(rev) { tree = vector<ll>(N + 3, -1e18); }
void upd(int i, ll v) {
if (!(0 <= i && i < N)) return;
if (rev) i = N - i - 1;
i++;
while (i <= N) {
tree[i] = max(tree[i], v);
i += i & -i;
}
}
ll get(int i) {
if (!(0 <= i && i < N)) return -1e18;
if (rev) i = N - i - 1;
i++;
ll ans = -1e18;
while (i) {
ans = max(ans, tree[i]);
i -= i & -i;
}
return ans;
}
};
ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
int i;
for (auto& v : X) v++;
for (auto& v : Y) v++;
for (i = 0; i < M; i++) locs[X[i]].emplace_back(Y[i], W[i]);
for (i = 0; i < N; i++) if (locs[i].size()) {
sort(locs[i].begin(), locs[i].end());
for (auto& [_, v] : locs[i]) sum[i] += v;
}
bit fenu(N, false), fend(N, true);
fenu.upd(0, 0);
for (i = 0; i <= N; i++) tdp[i] = bdp[i] = -1e18;
for (i = 1; i <= N; i++) {
if (i > 2) fend.upd(N + 1, tdp[i - 2]);
if (i > 3) fend.upd(N + 1, tdp[i - 3]);
if (i > 1) fenu.upd(0, bdp[i - 1]);
if (i > 1) fend.upd(N + 1, 0);
for (auto& [y, w] : locs[i]) fenu.upd(y, fenu.get(y - 1) + w);
tdp[i] = fenu.get(N + 1);
for (int j = locs[i].size() - 1; j >= 0; j--) {
ll y = locs[i][j].first;
ll w = locs[i][j].second;
fend.upd(y, fend.get(y + 1) + w);
}
bdp[i] = fend.get(0);
tdp[i] = max(tdp[i], sum[i] + tdp[i - 2]);
}
ll ans = fend.get(0);
for (i = 1; i < N; i++) ans = max(ans, tdp[i]);
for (i = 1; i <= N; i++) ans = max(ans, bdp[i]);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
12872 KB |
Output is correct |
2 |
Correct |
63 ms |
13688 KB |
Output is correct |
3 |
Correct |
22 ms |
10452 KB |
Output is correct |
4 |
Correct |
22 ms |
10452 KB |
Output is correct |
5 |
Correct |
146 ms |
20124 KB |
Output is correct |
6 |
Correct |
171 ms |
22692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
7380 KB |
Output is correct |
2 |
Correct |
88 ms |
15364 KB |
Output is correct |
3 |
Correct |
104 ms |
17024 KB |
Output is correct |
4 |
Correct |
52 ms |
12872 KB |
Output is correct |
5 |
Correct |
60 ms |
13760 KB |
Output is correct |
6 |
Correct |
4 ms |
7380 KB |
Output is correct |
7 |
Correct |
4 ms |
7416 KB |
Output is correct |
8 |
Correct |
4 ms |
7380 KB |
Output is correct |
9 |
Correct |
4 ms |
7380 KB |
Output is correct |
10 |
Correct |
22 ms |
10452 KB |
Output is correct |
11 |
Correct |
26 ms |
10476 KB |
Output is correct |
12 |
Correct |
56 ms |
12912 KB |
Output is correct |
13 |
Correct |
60 ms |
13820 KB |
Output is correct |
14 |
Correct |
54 ms |
12924 KB |
Output is correct |
15 |
Correct |
59 ms |
13584 KB |
Output is correct |
16 |
Correct |
56 ms |
13008 KB |
Output is correct |
17 |
Correct |
57 ms |
13588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
10452 KB |
Output is correct |
2 |
Correct |
27 ms |
10484 KB |
Output is correct |
3 |
Correct |
59 ms |
13872 KB |
Output is correct |
4 |
Correct |
37 ms |
13032 KB |
Output is correct |
5 |
Correct |
66 ms |
16716 KB |
Output is correct |
6 |
Correct |
60 ms |
16724 KB |
Output is correct |
7 |
Correct |
63 ms |
16768 KB |
Output is correct |
8 |
Correct |
79 ms |
16724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7380 KB |
Output is correct |
4 |
Correct |
4 ms |
7380 KB |
Output is correct |
5 |
Correct |
4 ms |
7380 KB |
Output is correct |
6 |
Correct |
4 ms |
7380 KB |
Output is correct |
7 |
Correct |
5 ms |
7380 KB |
Output is correct |
8 |
Correct |
4 ms |
7380 KB |
Output is correct |
9 |
Incorrect |
5 ms |
7380 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '216366270048' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7380 KB |
Output is correct |
4 |
Correct |
4 ms |
7380 KB |
Output is correct |
5 |
Correct |
4 ms |
7380 KB |
Output is correct |
6 |
Correct |
4 ms |
7380 KB |
Output is correct |
7 |
Correct |
5 ms |
7380 KB |
Output is correct |
8 |
Correct |
4 ms |
7380 KB |
Output is correct |
9 |
Incorrect |
5 ms |
7380 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '216366270048' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
4 ms |
7380 KB |
Output is correct |
3 |
Correct |
4 ms |
7380 KB |
Output is correct |
4 |
Correct |
4 ms |
7380 KB |
Output is correct |
5 |
Correct |
4 ms |
7380 KB |
Output is correct |
6 |
Correct |
4 ms |
7380 KB |
Output is correct |
7 |
Correct |
5 ms |
7380 KB |
Output is correct |
8 |
Correct |
4 ms |
7380 KB |
Output is correct |
9 |
Incorrect |
5 ms |
7380 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '216366270048' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
10452 KB |
Output is correct |
2 |
Correct |
27 ms |
10484 KB |
Output is correct |
3 |
Correct |
59 ms |
13872 KB |
Output is correct |
4 |
Correct |
37 ms |
13032 KB |
Output is correct |
5 |
Correct |
66 ms |
16716 KB |
Output is correct |
6 |
Correct |
60 ms |
16724 KB |
Output is correct |
7 |
Correct |
63 ms |
16768 KB |
Output is correct |
8 |
Correct |
79 ms |
16724 KB |
Output is correct |
9 |
Correct |
65 ms |
16776 KB |
Output is correct |
10 |
Correct |
59 ms |
13176 KB |
Output is correct |
11 |
Correct |
117 ms |
19100 KB |
Output is correct |
12 |
Correct |
5 ms |
7380 KB |
Output is correct |
13 |
Correct |
4 ms |
7380 KB |
Output is correct |
14 |
Correct |
5 ms |
7380 KB |
Output is correct |
15 |
Correct |
4 ms |
7380 KB |
Output is correct |
16 |
Correct |
4 ms |
7380 KB |
Output is correct |
17 |
Correct |
4 ms |
7380 KB |
Output is correct |
18 |
Correct |
22 ms |
10452 KB |
Output is correct |
19 |
Correct |
21 ms |
10452 KB |
Output is correct |
20 |
Correct |
21 ms |
10548 KB |
Output is correct |
21 |
Correct |
22 ms |
10452 KB |
Output is correct |
22 |
Incorrect |
70 ms |
15740 KB |
1st lines differ - on the 1st token, expected: '45561826463480', found: '45561636063706' |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
12872 KB |
Output is correct |
2 |
Correct |
63 ms |
13688 KB |
Output is correct |
3 |
Correct |
22 ms |
10452 KB |
Output is correct |
4 |
Correct |
22 ms |
10452 KB |
Output is correct |
5 |
Correct |
146 ms |
20124 KB |
Output is correct |
6 |
Correct |
171 ms |
22692 KB |
Output is correct |
7 |
Correct |
6 ms |
7380 KB |
Output is correct |
8 |
Correct |
88 ms |
15364 KB |
Output is correct |
9 |
Correct |
104 ms |
17024 KB |
Output is correct |
10 |
Correct |
52 ms |
12872 KB |
Output is correct |
11 |
Correct |
60 ms |
13760 KB |
Output is correct |
12 |
Correct |
4 ms |
7380 KB |
Output is correct |
13 |
Correct |
4 ms |
7416 KB |
Output is correct |
14 |
Correct |
4 ms |
7380 KB |
Output is correct |
15 |
Correct |
4 ms |
7380 KB |
Output is correct |
16 |
Correct |
22 ms |
10452 KB |
Output is correct |
17 |
Correct |
26 ms |
10476 KB |
Output is correct |
18 |
Correct |
56 ms |
12912 KB |
Output is correct |
19 |
Correct |
60 ms |
13820 KB |
Output is correct |
20 |
Correct |
54 ms |
12924 KB |
Output is correct |
21 |
Correct |
59 ms |
13584 KB |
Output is correct |
22 |
Correct |
56 ms |
13008 KB |
Output is correct |
23 |
Correct |
57 ms |
13588 KB |
Output is correct |
24 |
Correct |
22 ms |
10452 KB |
Output is correct |
25 |
Correct |
27 ms |
10484 KB |
Output is correct |
26 |
Correct |
59 ms |
13872 KB |
Output is correct |
27 |
Correct |
37 ms |
13032 KB |
Output is correct |
28 |
Correct |
66 ms |
16716 KB |
Output is correct |
29 |
Correct |
60 ms |
16724 KB |
Output is correct |
30 |
Correct |
63 ms |
16768 KB |
Output is correct |
31 |
Correct |
79 ms |
16724 KB |
Output is correct |
32 |
Correct |
4 ms |
7380 KB |
Output is correct |
33 |
Correct |
4 ms |
7380 KB |
Output is correct |
34 |
Correct |
4 ms |
7380 KB |
Output is correct |
35 |
Correct |
4 ms |
7380 KB |
Output is correct |
36 |
Correct |
4 ms |
7380 KB |
Output is correct |
37 |
Correct |
4 ms |
7380 KB |
Output is correct |
38 |
Correct |
5 ms |
7380 KB |
Output is correct |
39 |
Correct |
4 ms |
7380 KB |
Output is correct |
40 |
Incorrect |
5 ms |
7380 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '216366270048' |
41 |
Halted |
0 ms |
0 KB |
- |