#include "fish.h"
#include <vector>
using namespace std;
typedef vector<int> vi;
const int M = 300002;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
long long max(long long a, long long b) { return a > b ? a : b; }
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
int ii[M], ii1[M], jj[M], jj1[M], ww[M], ww1[M];
void sort(int *hh, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, h = hh[l + rand_() % (r - l)], tmp;
while (j < k) {
int c = ii1[hh[j]] != ii1[h] ? ii1[hh[j]] - ii1[h] : jj1[hh[j]] - jj1[h];
if (c == 0)
j++;
else if (c < 0) {
tmp = hh[i], hh[i] = hh[j], hh[j] = tmp;
i++, j++;
} else {
k--;
tmp = hh[j], hh[j] = hh[k], hh[k] = tmp;
}
}
sort(hh, l, i);
l = k;
}
}
long long dp[M], dq[M];
long long max_weights(int n, int m, vi ii_, vi jj_, vi ww_) {
static int hh[M];
for (int h = 0; h < m; h++)
ii1[h] = ii_[h], jj1[h] = jj_[h], ww1[h] = ww_[h];
ii1[m] = -1, jj1[m] = -1, ww1[m] = 0, m++;
ii1[m] = n, jj1[m] = -1, ww1[m] = 0, m++;
for (int h = 0; h < m; h++)
hh[h] = h;
sort(hh, 0, m);
for (int h = 0; h < m; h++)
ii[h] = ii1[hh[h]], jj[h] = jj1[hh[h]], ww[h] = ww1[hh[h]];
dp[0] = -INF, dq[0] = 0;
long long x = -INF, y;
for (int i = 0, l = 0, h = 1, r; i <= n; i++, l = h, h = r) {
r = h;
while (r < m && ii[r] == i)
r++;
y = x;
for (int f = h - 1, g = r - 1; g >= h; g--) {
while (f >= l && jj[f] > jj[g])
y = max(y, dp[f--]);
dp[g] = y;
if (dp[g] != -INF)
dp[g] += ww[g];
y = max(y, dp[g]);
}
for (int g = l; g < h; g++)
x = max(x, dp[g]);
y = x;
for (int f = l, g = h; g < r; g++) {
while (f < h && jj[f] < jj[g])
y = max(y, dq[f++]);
dq[g] = y;
if (dq[g] != -INF)
dq[g] += ww[g];
y = max(y, dq[g]);
}
for (int g = l; g < h; g++)
x = max(x, dq[g]);
}
return dp[m - 1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
5580 KB |
Output is correct |
2 |
Correct |
44 ms |
6920 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
146 ms |
20236 KB |
Output is correct |
6 |
Correct |
152 ms |
26580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
77 ms |
11084 KB |
Output is correct |
3 |
Correct |
100 ms |
16904 KB |
Output is correct |
4 |
Correct |
37 ms |
6776 KB |
Output is correct |
5 |
Correct |
46 ms |
8424 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
38 ms |
6844 KB |
Output is correct |
13 |
Correct |
46 ms |
8396 KB |
Output is correct |
14 |
Correct |
39 ms |
6832 KB |
Output is correct |
15 |
Correct |
47 ms |
7580 KB |
Output is correct |
16 |
Correct |
38 ms |
6860 KB |
Output is correct |
17 |
Correct |
42 ms |
7584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
21 ms |
3856 KB |
Output is correct |
4 |
Correct |
16 ms |
2660 KB |
Output is correct |
5 |
Correct |
42 ms |
6972 KB |
Output is correct |
6 |
Correct |
37 ms |
6928 KB |
Output is correct |
7 |
Correct |
41 ms |
6852 KB |
Output is correct |
8 |
Correct |
43 ms |
6920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
21 ms |
3272 KB |
Output is correct |
18 |
Correct |
24 ms |
3236 KB |
Output is correct |
19 |
Correct |
19 ms |
3272 KB |
Output is correct |
20 |
Correct |
21 ms |
3236 KB |
Output is correct |
21 |
Correct |
19 ms |
3264 KB |
Output is correct |
22 |
Correct |
39 ms |
6228 KB |
Output is correct |
23 |
Correct |
4 ms |
852 KB |
Output is correct |
24 |
Correct |
13 ms |
2260 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
4 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
21 ms |
3272 KB |
Output is correct |
18 |
Correct |
24 ms |
3236 KB |
Output is correct |
19 |
Correct |
19 ms |
3272 KB |
Output is correct |
20 |
Correct |
21 ms |
3236 KB |
Output is correct |
21 |
Correct |
19 ms |
3264 KB |
Output is correct |
22 |
Correct |
39 ms |
6228 KB |
Output is correct |
23 |
Correct |
4 ms |
852 KB |
Output is correct |
24 |
Correct |
13 ms |
2260 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
4 ms |
852 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
101 ms |
14640 KB |
Output is correct |
29 |
Correct |
145 ms |
24228 KB |
Output is correct |
30 |
Correct |
153 ms |
24128 KB |
Output is correct |
31 |
Correct |
152 ms |
25688 KB |
Output is correct |
32 |
Correct |
143 ms |
25076 KB |
Output is correct |
33 |
Correct |
152 ms |
25696 KB |
Output is correct |
34 |
Correct |
148 ms |
25060 KB |
Output is correct |
35 |
Correct |
54 ms |
9388 KB |
Output is correct |
36 |
Correct |
157 ms |
23612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
21 ms |
3856 KB |
Output is correct |
4 |
Correct |
16 ms |
2660 KB |
Output is correct |
5 |
Correct |
42 ms |
6972 KB |
Output is correct |
6 |
Correct |
37 ms |
6928 KB |
Output is correct |
7 |
Correct |
41 ms |
6852 KB |
Output is correct |
8 |
Correct |
43 ms |
6920 KB |
Output is correct |
9 |
Correct |
38 ms |
6928 KB |
Output is correct |
10 |
Correct |
43 ms |
6924 KB |
Output is correct |
11 |
Correct |
89 ms |
13548 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
300 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
304 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
48 ms |
8372 KB |
Output is correct |
23 |
Correct |
93 ms |
14648 KB |
Output is correct |
24 |
Correct |
93 ms |
15440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
5580 KB |
Output is correct |
2 |
Correct |
44 ms |
6920 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
146 ms |
20236 KB |
Output is correct |
6 |
Correct |
152 ms |
26580 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
77 ms |
11084 KB |
Output is correct |
9 |
Correct |
100 ms |
16904 KB |
Output is correct |
10 |
Correct |
37 ms |
6776 KB |
Output is correct |
11 |
Correct |
46 ms |
8424 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
38 ms |
6844 KB |
Output is correct |
19 |
Correct |
46 ms |
8396 KB |
Output is correct |
20 |
Correct |
39 ms |
6832 KB |
Output is correct |
21 |
Correct |
47 ms |
7580 KB |
Output is correct |
22 |
Correct |
38 ms |
6860 KB |
Output is correct |
23 |
Correct |
42 ms |
7584 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
21 ms |
3856 KB |
Output is correct |
27 |
Correct |
16 ms |
2660 KB |
Output is correct |
28 |
Correct |
42 ms |
6972 KB |
Output is correct |
29 |
Correct |
37 ms |
6928 KB |
Output is correct |
30 |
Correct |
41 ms |
6852 KB |
Output is correct |
31 |
Correct |
43 ms |
6920 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
340 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
0 ms |
340 KB |
Output is correct |
37 |
Correct |
0 ms |
340 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
0 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
468 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
0 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
0 ms |
340 KB |
Output is correct |
47 |
Correct |
2 ms |
468 KB |
Output is correct |
48 |
Correct |
21 ms |
3272 KB |
Output is correct |
49 |
Correct |
24 ms |
3236 KB |
Output is correct |
50 |
Correct |
19 ms |
3272 KB |
Output is correct |
51 |
Correct |
21 ms |
3236 KB |
Output is correct |
52 |
Correct |
19 ms |
3264 KB |
Output is correct |
53 |
Correct |
39 ms |
6228 KB |
Output is correct |
54 |
Correct |
4 ms |
852 KB |
Output is correct |
55 |
Correct |
13 ms |
2260 KB |
Output is correct |
56 |
Correct |
1 ms |
340 KB |
Output is correct |
57 |
Correct |
4 ms |
852 KB |
Output is correct |
58 |
Correct |
2 ms |
468 KB |
Output is correct |
59 |
Correct |
101 ms |
14640 KB |
Output is correct |
60 |
Correct |
145 ms |
24228 KB |
Output is correct |
61 |
Correct |
153 ms |
24128 KB |
Output is correct |
62 |
Correct |
152 ms |
25688 KB |
Output is correct |
63 |
Correct |
143 ms |
25076 KB |
Output is correct |
64 |
Correct |
152 ms |
25696 KB |
Output is correct |
65 |
Correct |
148 ms |
25060 KB |
Output is correct |
66 |
Correct |
54 ms |
9388 KB |
Output is correct |
67 |
Correct |
157 ms |
23612 KB |
Output is correct |
68 |
Correct |
38 ms |
6928 KB |
Output is correct |
69 |
Correct |
43 ms |
6924 KB |
Output is correct |
70 |
Correct |
89 ms |
13548 KB |
Output is correct |
71 |
Correct |
0 ms |
340 KB |
Output is correct |
72 |
Correct |
0 ms |
300 KB |
Output is correct |
73 |
Correct |
0 ms |
340 KB |
Output is correct |
74 |
Correct |
1 ms |
340 KB |
Output is correct |
75 |
Correct |
0 ms |
340 KB |
Output is correct |
76 |
Correct |
0 ms |
340 KB |
Output is correct |
77 |
Correct |
1 ms |
340 KB |
Output is correct |
78 |
Correct |
1 ms |
348 KB |
Output is correct |
79 |
Correct |
1 ms |
304 KB |
Output is correct |
80 |
Correct |
1 ms |
340 KB |
Output is correct |
81 |
Correct |
48 ms |
8372 KB |
Output is correct |
82 |
Correct |
93 ms |
14648 KB |
Output is correct |
83 |
Correct |
93 ms |
15440 KB |
Output is correct |
84 |
Correct |
166 ms |
22896 KB |
Output is correct |
85 |
Correct |
148 ms |
22764 KB |
Output is correct |
86 |
Correct |
153 ms |
21240 KB |
Output is correct |
87 |
Correct |
181 ms |
20716 KB |
Output is correct |
88 |
Correct |
0 ms |
340 KB |
Output is correct |
89 |
Correct |
151 ms |
21356 KB |
Output is correct |
90 |
Correct |
151 ms |
20524 KB |
Output is correct |
91 |
Correct |
138 ms |
20572 KB |
Output is correct |