#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
typedef long long ll;
const int N = 100005;
int n, m;
vector<pair<int, int> > v[N];
vector<ll> dp0[N], dp1[N];
long long max_weights(int NN, int MM, std::vector<int> XX, std::vector<int> YY, std::vector<int> WW)
{
n = NN;
m = MM;
for (int i = 0; i < m; ++i)
{
v[XX[i] + 1].push_back(m_p(YY[i], WW[i]));
}
v[0].push_back(m_p(0, 0));
for (int i = 1; i <= n; ++i)
{
sort(all(v[i]));
v[i].push_back(m_p(n, 0));
}
dp0[0].push_back(0);
dp1[0].push_back(0);
for (int i = 1; i <= n; ++i)
{
ll maxu = 0;
for (int j = 0; j < sz(v[i - 1]); ++j)
{
maxu = max(maxu, dp0[i - 1][j]);
}
dp0[i].assign(sz(v[i]), maxu);
dp1[i].assign(sz(v[i]), maxu);
vector<ll> p;
p.assign(sz(v[i]), 0);
p[0] = v[i][0].se;
for (int j = 1; j < sz(v[i]); ++j)
p[j] = p[j - 1] + v[i][j].se;
int k = sz(v[i - 1]) - 1;
maxu = 0;
for (int j = sz(v[i]) - 1; j >= 0; --j)
{
while (k >= 0 && v[i - 1][k].fi > v[i][j].fi)
{
maxu = max(maxu, p[j] + dp0[i - 1][k]);
--k;
}
if (j)
dp0[i][j] = max(dp0[i][j], maxu - p[j - 1]);
else
dp0[i][j] = max(dp0[i][j], maxu);
}
k = 0;
maxu = 0;
ll pp = 0;
for (int j = 0; j < sz(v[i]); ++j)
{
while (k < sz(v[i - 1]) && v[i - 1][k].fi < v[i][j].fi)
{
maxu = max(maxu, dp1[i - 1][k] - pp);
pp += v[i - 1][k].se;
++k;
}
dp1[i][j] = max(dp1[i][j], pp + maxu);
}
for (int j = 0; j < sz(v[i]); ++j)
dp0[i][j] = max(dp0[i][j], dp1[i][j]);
}
ll ans = 0;
for (int j = 0; j < sz(v[n]); ++j)
{
ans = max(ans, dp0[n][j]);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
19576 KB |
Output is correct |
2 |
Correct |
47 ms |
21344 KB |
Output is correct |
3 |
Correct |
17 ms |
16676 KB |
Output is correct |
4 |
Correct |
16 ms |
16724 KB |
Output is correct |
5 |
Correct |
108 ms |
31116 KB |
Output is correct |
6 |
Correct |
120 ms |
30324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7252 KB |
Output is correct |
2 |
Correct |
66 ms |
23364 KB |
Output is correct |
3 |
Correct |
79 ms |
26108 KB |
Output is correct |
4 |
Correct |
40 ms |
19492 KB |
Output is correct |
5 |
Correct |
49 ms |
21372 KB |
Output is correct |
6 |
Correct |
3 ms |
7252 KB |
Output is correct |
7 |
Correct |
3 ms |
7252 KB |
Output is correct |
8 |
Correct |
3 ms |
7252 KB |
Output is correct |
9 |
Correct |
3 ms |
7304 KB |
Output is correct |
10 |
Correct |
17 ms |
16736 KB |
Output is correct |
11 |
Correct |
16 ms |
16740 KB |
Output is correct |
12 |
Correct |
38 ms |
19560 KB |
Output is correct |
13 |
Correct |
45 ms |
21432 KB |
Output is correct |
14 |
Correct |
40 ms |
19600 KB |
Output is correct |
15 |
Correct |
44 ms |
20928 KB |
Output is correct |
16 |
Correct |
41 ms |
19624 KB |
Output is correct |
17 |
Correct |
45 ms |
20836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
16744 KB |
Output is correct |
2 |
Correct |
22 ms |
16620 KB |
Output is correct |
3 |
Correct |
35 ms |
16936 KB |
Output is correct |
4 |
Correct |
27 ms |
18128 KB |
Output is correct |
5 |
Correct |
48 ms |
20592 KB |
Output is correct |
6 |
Correct |
44 ms |
20032 KB |
Output is correct |
7 |
Correct |
45 ms |
20620 KB |
Output is correct |
8 |
Correct |
57 ms |
20572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7252 KB |
Output is correct |
2 |
Correct |
3 ms |
7252 KB |
Output is correct |
3 |
Correct |
3 ms |
7260 KB |
Output is correct |
4 |
Correct |
3 ms |
7252 KB |
Output is correct |
5 |
Correct |
3 ms |
7252 KB |
Output is correct |
6 |
Correct |
3 ms |
7252 KB |
Output is correct |
7 |
Correct |
3 ms |
7252 KB |
Output is correct |
8 |
Correct |
3 ms |
7252 KB |
Output is correct |
9 |
Correct |
3 ms |
7380 KB |
Output is correct |
10 |
Correct |
4 ms |
7536 KB |
Output is correct |
11 |
Correct |
4 ms |
7380 KB |
Output is correct |
12 |
Correct |
4 ms |
7380 KB |
Output is correct |
13 |
Correct |
5 ms |
7252 KB |
Output is correct |
14 |
Correct |
5 ms |
7336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7252 KB |
Output is correct |
2 |
Correct |
3 ms |
7252 KB |
Output is correct |
3 |
Correct |
3 ms |
7260 KB |
Output is correct |
4 |
Correct |
3 ms |
7252 KB |
Output is correct |
5 |
Correct |
3 ms |
7252 KB |
Output is correct |
6 |
Correct |
3 ms |
7252 KB |
Output is correct |
7 |
Correct |
3 ms |
7252 KB |
Output is correct |
8 |
Correct |
3 ms |
7252 KB |
Output is correct |
9 |
Correct |
3 ms |
7380 KB |
Output is correct |
10 |
Correct |
4 ms |
7536 KB |
Output is correct |
11 |
Correct |
4 ms |
7380 KB |
Output is correct |
12 |
Correct |
4 ms |
7380 KB |
Output is correct |
13 |
Correct |
5 ms |
7252 KB |
Output is correct |
14 |
Correct |
5 ms |
7336 KB |
Output is correct |
15 |
Correct |
3 ms |
7344 KB |
Output is correct |
16 |
Correct |
4 ms |
7488 KB |
Output is correct |
17 |
Correct |
16 ms |
10316 KB |
Output is correct |
18 |
Correct |
16 ms |
10560 KB |
Output is correct |
19 |
Correct |
16 ms |
10644 KB |
Output is correct |
20 |
Correct |
18 ms |
10556 KB |
Output is correct |
21 |
Correct |
15 ms |
10436 KB |
Output is correct |
22 |
Correct |
28 ms |
13628 KB |
Output is correct |
23 |
Correct |
8 ms |
8068 KB |
Output is correct |
24 |
Correct |
14 ms |
9300 KB |
Output is correct |
25 |
Correct |
4 ms |
7380 KB |
Output is correct |
26 |
Correct |
5 ms |
7868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7252 KB |
Output is correct |
2 |
Correct |
3 ms |
7252 KB |
Output is correct |
3 |
Correct |
3 ms |
7260 KB |
Output is correct |
4 |
Correct |
3 ms |
7252 KB |
Output is correct |
5 |
Correct |
3 ms |
7252 KB |
Output is correct |
6 |
Correct |
3 ms |
7252 KB |
Output is correct |
7 |
Correct |
3 ms |
7252 KB |
Output is correct |
8 |
Correct |
3 ms |
7252 KB |
Output is correct |
9 |
Correct |
3 ms |
7380 KB |
Output is correct |
10 |
Correct |
4 ms |
7536 KB |
Output is correct |
11 |
Correct |
4 ms |
7380 KB |
Output is correct |
12 |
Correct |
4 ms |
7380 KB |
Output is correct |
13 |
Correct |
5 ms |
7252 KB |
Output is correct |
14 |
Correct |
5 ms |
7336 KB |
Output is correct |
15 |
Correct |
3 ms |
7344 KB |
Output is correct |
16 |
Correct |
4 ms |
7488 KB |
Output is correct |
17 |
Correct |
16 ms |
10316 KB |
Output is correct |
18 |
Correct |
16 ms |
10560 KB |
Output is correct |
19 |
Correct |
16 ms |
10644 KB |
Output is correct |
20 |
Correct |
18 ms |
10556 KB |
Output is correct |
21 |
Correct |
15 ms |
10436 KB |
Output is correct |
22 |
Correct |
28 ms |
13628 KB |
Output is correct |
23 |
Correct |
8 ms |
8068 KB |
Output is correct |
24 |
Correct |
14 ms |
9300 KB |
Output is correct |
25 |
Correct |
4 ms |
7380 KB |
Output is correct |
26 |
Correct |
5 ms |
7868 KB |
Output is correct |
27 |
Correct |
5 ms |
7688 KB |
Output is correct |
28 |
Correct |
63 ms |
22660 KB |
Output is correct |
29 |
Correct |
91 ms |
28332 KB |
Output is correct |
30 |
Correct |
90 ms |
27992 KB |
Output is correct |
31 |
Correct |
93 ms |
28000 KB |
Output is correct |
32 |
Correct |
87 ms |
28876 KB |
Output is correct |
33 |
Correct |
89 ms |
28024 KB |
Output is correct |
34 |
Correct |
90 ms |
27992 KB |
Output is correct |
35 |
Correct |
37 ms |
15436 KB |
Output is correct |
36 |
Correct |
89 ms |
28504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
16744 KB |
Output is correct |
2 |
Correct |
22 ms |
16620 KB |
Output is correct |
3 |
Correct |
35 ms |
16936 KB |
Output is correct |
4 |
Correct |
27 ms |
18128 KB |
Output is correct |
5 |
Correct |
48 ms |
20592 KB |
Output is correct |
6 |
Correct |
44 ms |
20032 KB |
Output is correct |
7 |
Correct |
45 ms |
20620 KB |
Output is correct |
8 |
Correct |
57 ms |
20572 KB |
Output is correct |
9 |
Correct |
41 ms |
20404 KB |
Output is correct |
10 |
Correct |
50 ms |
17100 KB |
Output is correct |
11 |
Correct |
79 ms |
26976 KB |
Output is correct |
12 |
Correct |
3 ms |
7352 KB |
Output is correct |
13 |
Correct |
3 ms |
7352 KB |
Output is correct |
14 |
Correct |
3 ms |
7252 KB |
Output is correct |
15 |
Correct |
4 ms |
7344 KB |
Output is correct |
16 |
Correct |
3 ms |
7252 KB |
Output is correct |
17 |
Correct |
3 ms |
7348 KB |
Output is correct |
18 |
Correct |
15 ms |
16628 KB |
Output is correct |
19 |
Correct |
16 ms |
16692 KB |
Output is correct |
20 |
Correct |
21 ms |
16748 KB |
Output is correct |
21 |
Correct |
16 ms |
16724 KB |
Output is correct |
22 |
Correct |
49 ms |
21692 KB |
Output is correct |
23 |
Correct |
80 ms |
26952 KB |
Output is correct |
24 |
Correct |
81 ms |
27468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
19576 KB |
Output is correct |
2 |
Correct |
47 ms |
21344 KB |
Output is correct |
3 |
Correct |
17 ms |
16676 KB |
Output is correct |
4 |
Correct |
16 ms |
16724 KB |
Output is correct |
5 |
Correct |
108 ms |
31116 KB |
Output is correct |
6 |
Correct |
120 ms |
30324 KB |
Output is correct |
7 |
Correct |
3 ms |
7252 KB |
Output is correct |
8 |
Correct |
66 ms |
23364 KB |
Output is correct |
9 |
Correct |
79 ms |
26108 KB |
Output is correct |
10 |
Correct |
40 ms |
19492 KB |
Output is correct |
11 |
Correct |
49 ms |
21372 KB |
Output is correct |
12 |
Correct |
3 ms |
7252 KB |
Output is correct |
13 |
Correct |
3 ms |
7252 KB |
Output is correct |
14 |
Correct |
3 ms |
7252 KB |
Output is correct |
15 |
Correct |
3 ms |
7304 KB |
Output is correct |
16 |
Correct |
17 ms |
16736 KB |
Output is correct |
17 |
Correct |
16 ms |
16740 KB |
Output is correct |
18 |
Correct |
38 ms |
19560 KB |
Output is correct |
19 |
Correct |
45 ms |
21432 KB |
Output is correct |
20 |
Correct |
40 ms |
19600 KB |
Output is correct |
21 |
Correct |
44 ms |
20928 KB |
Output is correct |
22 |
Correct |
41 ms |
19624 KB |
Output is correct |
23 |
Correct |
45 ms |
20836 KB |
Output is correct |
24 |
Correct |
21 ms |
16744 KB |
Output is correct |
25 |
Correct |
22 ms |
16620 KB |
Output is correct |
26 |
Correct |
35 ms |
16936 KB |
Output is correct |
27 |
Correct |
27 ms |
18128 KB |
Output is correct |
28 |
Correct |
48 ms |
20592 KB |
Output is correct |
29 |
Correct |
44 ms |
20032 KB |
Output is correct |
30 |
Correct |
45 ms |
20620 KB |
Output is correct |
31 |
Correct |
57 ms |
20572 KB |
Output is correct |
32 |
Correct |
3 ms |
7252 KB |
Output is correct |
33 |
Correct |
3 ms |
7252 KB |
Output is correct |
34 |
Correct |
3 ms |
7260 KB |
Output is correct |
35 |
Correct |
3 ms |
7252 KB |
Output is correct |
36 |
Correct |
3 ms |
7252 KB |
Output is correct |
37 |
Correct |
3 ms |
7252 KB |
Output is correct |
38 |
Correct |
3 ms |
7252 KB |
Output is correct |
39 |
Correct |
3 ms |
7252 KB |
Output is correct |
40 |
Correct |
3 ms |
7380 KB |
Output is correct |
41 |
Correct |
4 ms |
7536 KB |
Output is correct |
42 |
Correct |
4 ms |
7380 KB |
Output is correct |
43 |
Correct |
4 ms |
7380 KB |
Output is correct |
44 |
Correct |
5 ms |
7252 KB |
Output is correct |
45 |
Correct |
5 ms |
7336 KB |
Output is correct |
46 |
Correct |
3 ms |
7344 KB |
Output is correct |
47 |
Correct |
4 ms |
7488 KB |
Output is correct |
48 |
Correct |
16 ms |
10316 KB |
Output is correct |
49 |
Correct |
16 ms |
10560 KB |
Output is correct |
50 |
Correct |
16 ms |
10644 KB |
Output is correct |
51 |
Correct |
18 ms |
10556 KB |
Output is correct |
52 |
Correct |
15 ms |
10436 KB |
Output is correct |
53 |
Correct |
28 ms |
13628 KB |
Output is correct |
54 |
Correct |
8 ms |
8068 KB |
Output is correct |
55 |
Correct |
14 ms |
9300 KB |
Output is correct |
56 |
Correct |
4 ms |
7380 KB |
Output is correct |
57 |
Correct |
5 ms |
7868 KB |
Output is correct |
58 |
Correct |
5 ms |
7688 KB |
Output is correct |
59 |
Correct |
63 ms |
22660 KB |
Output is correct |
60 |
Correct |
91 ms |
28332 KB |
Output is correct |
61 |
Correct |
90 ms |
27992 KB |
Output is correct |
62 |
Correct |
93 ms |
28000 KB |
Output is correct |
63 |
Correct |
87 ms |
28876 KB |
Output is correct |
64 |
Correct |
89 ms |
28024 KB |
Output is correct |
65 |
Correct |
90 ms |
27992 KB |
Output is correct |
66 |
Correct |
37 ms |
15436 KB |
Output is correct |
67 |
Correct |
89 ms |
28504 KB |
Output is correct |
68 |
Correct |
41 ms |
20404 KB |
Output is correct |
69 |
Correct |
50 ms |
17100 KB |
Output is correct |
70 |
Correct |
79 ms |
26976 KB |
Output is correct |
71 |
Correct |
3 ms |
7352 KB |
Output is correct |
72 |
Correct |
3 ms |
7352 KB |
Output is correct |
73 |
Correct |
3 ms |
7252 KB |
Output is correct |
74 |
Correct |
4 ms |
7344 KB |
Output is correct |
75 |
Correct |
3 ms |
7252 KB |
Output is correct |
76 |
Correct |
3 ms |
7348 KB |
Output is correct |
77 |
Correct |
15 ms |
16628 KB |
Output is correct |
78 |
Correct |
16 ms |
16692 KB |
Output is correct |
79 |
Correct |
21 ms |
16748 KB |
Output is correct |
80 |
Correct |
16 ms |
16724 KB |
Output is correct |
81 |
Correct |
49 ms |
21692 KB |
Output is correct |
82 |
Correct |
80 ms |
26952 KB |
Output is correct |
83 |
Correct |
81 ms |
27468 KB |
Output is correct |
84 |
Correct |
108 ms |
36260 KB |
Output is correct |
85 |
Correct |
109 ms |
36460 KB |
Output is correct |
86 |
Correct |
111 ms |
34252 KB |
Output is correct |
87 |
Correct |
119 ms |
35204 KB |
Output is correct |
88 |
Correct |
3 ms |
7252 KB |
Output is correct |
89 |
Correct |
117 ms |
35164 KB |
Output is correct |
90 |
Correct |
116 ms |
35672 KB |
Output is correct |
91 |
Correct |
110 ms |
36228 KB |
Output is correct |