#include "fish.h"
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
// <|°_°|>
// M. Broccoli
// The hardest choices require the strongest wills
// What is better - to be born good, or to overcome your evil nature with great effort ?
const int MAX_ROWS = (1e5 + 1);
vector <long long> DP_Built[MAX_ROWS];
vector <long long> DP_Free[MAX_ROWS];
vector <pair <int, long long>> CatFishs[MAX_ROWS];
long long max_weights(int nbRows, int nbCatfishs, vector <int> Col, vector <int> Row,
vector <int> Weight) {
for (int i = 0; i < nbCatfishs; i ++)
{
CatFishs[Col[i] + 1].push_back({Row[i], Weight[i]});
}
for (int i = 0; i <= nbRows; i ++)
{
CatFishs[i].push_back({-1, 0});
if (i)
CatFishs[i].push_back({MAX_ROWS, 0});
sort(CatFishs[i].begin(), CatFishs[i].end());
DP_Built[i].resize(CatFishs[i].size());
DP_Free[i].resize(CatFishs[i].size());
}
DP_Built[0] = {0};
DP_Free[0] = {0};
for (int i = 1; i <= nbRows; i ++)
{
long long maxiFree = - (1LL << 60);
long long maxiBuilt = - (1LL << 60);
int prev = 0;
int sz = CatFishs[i - 1].size();
int curSz = CatFishs[i].size();
for (int fish = 0; fish < curSz - 1; fish ++)
{
while (prev < sz && CatFishs[i - 1][prev].first < CatFishs[i][fish + 1].first)
{
maxiBuilt = max(maxiBuilt, DP_Built[i - 1][prev]);
maxiFree = max(maxiFree, DP_Free[i - 1][prev]);
maxiFree += CatFishs[i - 1][prev ++].second;
}
DP_Built[i][fish] = max(maxiBuilt, maxiFree);
DP_Free[i][fish + 1] = max(maxiBuilt, maxiFree);
}
maxiBuilt = - (1LL << 60);
prev = sz - 1;
for (int fish = curSz - 2; fish >= 0; fish --)
{
while (prev && CatFishs[i - 1][prev].first > CatFishs[i][fish + 1].first)
maxiBuilt = max(maxiBuilt, DP_Built[i - 1][-- prev]);
maxiBuilt += CatFishs[i][fish + 1].second;
DP_Built[i][fish] = max(DP_Built[i][fish], maxiBuilt);
}
prev = 1;
maxiFree = 0;
for (int fish = 1; fish < curSz; fish ++)
{
maxiBuilt = - (1LL << 60);
while (prev < sz && CatFishs[i - 1][prev + 1].first <= CatFishs[i][fish].first)
maxiBuilt = max(maxiBuilt, DP_Built[i - 1][prev ++]);
maxiFree += CatFishs[i][fish - 1].second;
DP_Free[i][fish] = max(DP_Free[i][fish], maxiBuilt + maxiFree);
}
}
long long ans = 0;
for (long long a : DP_Built[nbRows])
ans = max(ans, a);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
22732 KB |
Output is correct |
2 |
Correct |
71 ms |
25236 KB |
Output is correct |
3 |
Correct |
28 ms |
18224 KB |
Output is correct |
4 |
Correct |
31 ms |
18260 KB |
Output is correct |
5 |
Correct |
148 ms |
40676 KB |
Output is correct |
6 |
Correct |
170 ms |
43196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7380 KB |
Output is correct |
2 |
Correct |
109 ms |
28564 KB |
Output is correct |
3 |
Correct |
115 ms |
32420 KB |
Output is correct |
4 |
Correct |
58 ms |
22708 KB |
Output is correct |
5 |
Correct |
68 ms |
25276 KB |
Output is correct |
6 |
Correct |
4 ms |
7252 KB |
Output is correct |
7 |
Correct |
4 ms |
7288 KB |
Output is correct |
8 |
Correct |
4 ms |
7252 KB |
Output is correct |
9 |
Correct |
4 ms |
7256 KB |
Output is correct |
10 |
Correct |
27 ms |
18304 KB |
Output is correct |
11 |
Correct |
29 ms |
18308 KB |
Output is correct |
12 |
Correct |
60 ms |
22692 KB |
Output is correct |
13 |
Correct |
68 ms |
25212 KB |
Output is correct |
14 |
Correct |
58 ms |
22712 KB |
Output is correct |
15 |
Correct |
68 ms |
24644 KB |
Output is correct |
16 |
Correct |
62 ms |
22704 KB |
Output is correct |
17 |
Correct |
67 ms |
24504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
18260 KB |
Output is correct |
2 |
Correct |
28 ms |
18296 KB |
Output is correct |
3 |
Correct |
49 ms |
20816 KB |
Output is correct |
4 |
Correct |
43 ms |
20320 KB |
Output is correct |
5 |
Correct |
74 ms |
23884 KB |
Output is correct |
6 |
Correct |
70 ms |
24304 KB |
Output is correct |
7 |
Correct |
89 ms |
24452 KB |
Output is correct |
8 |
Correct |
69 ms |
24408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7252 KB |
Output is correct |
2 |
Correct |
3 ms |
7252 KB |
Output is correct |
3 |
Correct |
4 ms |
7296 KB |
Output is correct |
4 |
Correct |
4 ms |
7252 KB |
Output is correct |
5 |
Correct |
4 ms |
7252 KB |
Output is correct |
6 |
Correct |
4 ms |
7252 KB |
Output is correct |
7 |
Correct |
4 ms |
7252 KB |
Output is correct |
8 |
Correct |
4 ms |
7252 KB |
Output is correct |
9 |
Correct |
6 ms |
7380 KB |
Output is correct |
10 |
Correct |
5 ms |
7508 KB |
Output is correct |
11 |
Correct |
5 ms |
7380 KB |
Output is correct |
12 |
Correct |
5 ms |
7380 KB |
Output is correct |
13 |
Correct |
5 ms |
7252 KB |
Output is correct |
14 |
Correct |
5 ms |
7380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7252 KB |
Output is correct |
2 |
Correct |
3 ms |
7252 KB |
Output is correct |
3 |
Correct |
4 ms |
7296 KB |
Output is correct |
4 |
Correct |
4 ms |
7252 KB |
Output is correct |
5 |
Correct |
4 ms |
7252 KB |
Output is correct |
6 |
Correct |
4 ms |
7252 KB |
Output is correct |
7 |
Correct |
4 ms |
7252 KB |
Output is correct |
8 |
Correct |
4 ms |
7252 KB |
Output is correct |
9 |
Correct |
6 ms |
7380 KB |
Output is correct |
10 |
Correct |
5 ms |
7508 KB |
Output is correct |
11 |
Correct |
5 ms |
7380 KB |
Output is correct |
12 |
Correct |
5 ms |
7380 KB |
Output is correct |
13 |
Correct |
5 ms |
7252 KB |
Output is correct |
14 |
Correct |
5 ms |
7380 KB |
Output is correct |
15 |
Correct |
5 ms |
7312 KB |
Output is correct |
16 |
Correct |
5 ms |
7380 KB |
Output is correct |
17 |
Correct |
20 ms |
10544 KB |
Output is correct |
18 |
Correct |
20 ms |
11044 KB |
Output is correct |
19 |
Correct |
20 ms |
11016 KB |
Output is correct |
20 |
Correct |
20 ms |
11056 KB |
Output is correct |
21 |
Correct |
21 ms |
11024 KB |
Output is correct |
22 |
Correct |
34 ms |
14772 KB |
Output is correct |
23 |
Correct |
9 ms |
7892 KB |
Output is correct |
24 |
Correct |
14 ms |
9524 KB |
Output is correct |
25 |
Correct |
4 ms |
7380 KB |
Output is correct |
26 |
Correct |
7 ms |
7892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7252 KB |
Output is correct |
2 |
Correct |
3 ms |
7252 KB |
Output is correct |
3 |
Correct |
4 ms |
7296 KB |
Output is correct |
4 |
Correct |
4 ms |
7252 KB |
Output is correct |
5 |
Correct |
4 ms |
7252 KB |
Output is correct |
6 |
Correct |
4 ms |
7252 KB |
Output is correct |
7 |
Correct |
4 ms |
7252 KB |
Output is correct |
8 |
Correct |
4 ms |
7252 KB |
Output is correct |
9 |
Correct |
6 ms |
7380 KB |
Output is correct |
10 |
Correct |
5 ms |
7508 KB |
Output is correct |
11 |
Correct |
5 ms |
7380 KB |
Output is correct |
12 |
Correct |
5 ms |
7380 KB |
Output is correct |
13 |
Correct |
5 ms |
7252 KB |
Output is correct |
14 |
Correct |
5 ms |
7380 KB |
Output is correct |
15 |
Correct |
5 ms |
7312 KB |
Output is correct |
16 |
Correct |
5 ms |
7380 KB |
Output is correct |
17 |
Correct |
20 ms |
10544 KB |
Output is correct |
18 |
Correct |
20 ms |
11044 KB |
Output is correct |
19 |
Correct |
20 ms |
11016 KB |
Output is correct |
20 |
Correct |
20 ms |
11056 KB |
Output is correct |
21 |
Correct |
21 ms |
11024 KB |
Output is correct |
22 |
Correct |
34 ms |
14772 KB |
Output is correct |
23 |
Correct |
9 ms |
7892 KB |
Output is correct |
24 |
Correct |
14 ms |
9524 KB |
Output is correct |
25 |
Correct |
4 ms |
7380 KB |
Output is correct |
26 |
Correct |
7 ms |
7892 KB |
Output is correct |
27 |
Correct |
6 ms |
7764 KB |
Output is correct |
28 |
Correct |
81 ms |
24880 KB |
Output is correct |
29 |
Correct |
123 ms |
30256 KB |
Output is correct |
30 |
Correct |
123 ms |
29920 KB |
Output is correct |
31 |
Correct |
115 ms |
30828 KB |
Output is correct |
32 |
Correct |
105 ms |
32048 KB |
Output is correct |
33 |
Correct |
114 ms |
30924 KB |
Output is correct |
34 |
Correct |
116 ms |
30276 KB |
Output is correct |
35 |
Correct |
48 ms |
16380 KB |
Output is correct |
36 |
Correct |
124 ms |
30336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
18260 KB |
Output is correct |
2 |
Correct |
28 ms |
18296 KB |
Output is correct |
3 |
Correct |
49 ms |
20816 KB |
Output is correct |
4 |
Correct |
43 ms |
20320 KB |
Output is correct |
5 |
Correct |
74 ms |
23884 KB |
Output is correct |
6 |
Correct |
70 ms |
24304 KB |
Output is correct |
7 |
Correct |
89 ms |
24452 KB |
Output is correct |
8 |
Correct |
69 ms |
24408 KB |
Output is correct |
9 |
Correct |
70 ms |
24192 KB |
Output is correct |
10 |
Correct |
56 ms |
19464 KB |
Output is correct |
11 |
Correct |
134 ms |
32136 KB |
Output is correct |
12 |
Correct |
4 ms |
7252 KB |
Output is correct |
13 |
Correct |
4 ms |
7252 KB |
Output is correct |
14 |
Correct |
4 ms |
7340 KB |
Output is correct |
15 |
Correct |
4 ms |
7352 KB |
Output is correct |
16 |
Correct |
4 ms |
7252 KB |
Output is correct |
17 |
Correct |
3 ms |
7252 KB |
Output is correct |
18 |
Correct |
29 ms |
18224 KB |
Output is correct |
19 |
Correct |
26 ms |
18232 KB |
Output is correct |
20 |
Correct |
27 ms |
18260 KB |
Output is correct |
21 |
Correct |
27 ms |
18260 KB |
Output is correct |
22 |
Correct |
85 ms |
25124 KB |
Output is correct |
23 |
Correct |
109 ms |
30484 KB |
Output is correct |
24 |
Correct |
124 ms |
31472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
22732 KB |
Output is correct |
2 |
Correct |
71 ms |
25236 KB |
Output is correct |
3 |
Correct |
28 ms |
18224 KB |
Output is correct |
4 |
Correct |
31 ms |
18260 KB |
Output is correct |
5 |
Correct |
148 ms |
40676 KB |
Output is correct |
6 |
Correct |
170 ms |
43196 KB |
Output is correct |
7 |
Correct |
4 ms |
7380 KB |
Output is correct |
8 |
Correct |
109 ms |
28564 KB |
Output is correct |
9 |
Correct |
115 ms |
32420 KB |
Output is correct |
10 |
Correct |
58 ms |
22708 KB |
Output is correct |
11 |
Correct |
68 ms |
25276 KB |
Output is correct |
12 |
Correct |
4 ms |
7252 KB |
Output is correct |
13 |
Correct |
4 ms |
7288 KB |
Output is correct |
14 |
Correct |
4 ms |
7252 KB |
Output is correct |
15 |
Correct |
4 ms |
7256 KB |
Output is correct |
16 |
Correct |
27 ms |
18304 KB |
Output is correct |
17 |
Correct |
29 ms |
18308 KB |
Output is correct |
18 |
Correct |
60 ms |
22692 KB |
Output is correct |
19 |
Correct |
68 ms |
25212 KB |
Output is correct |
20 |
Correct |
58 ms |
22712 KB |
Output is correct |
21 |
Correct |
68 ms |
24644 KB |
Output is correct |
22 |
Correct |
62 ms |
22704 KB |
Output is correct |
23 |
Correct |
67 ms |
24504 KB |
Output is correct |
24 |
Correct |
29 ms |
18260 KB |
Output is correct |
25 |
Correct |
28 ms |
18296 KB |
Output is correct |
26 |
Correct |
49 ms |
20816 KB |
Output is correct |
27 |
Correct |
43 ms |
20320 KB |
Output is correct |
28 |
Correct |
74 ms |
23884 KB |
Output is correct |
29 |
Correct |
70 ms |
24304 KB |
Output is correct |
30 |
Correct |
89 ms |
24452 KB |
Output is correct |
31 |
Correct |
69 ms |
24408 KB |
Output is correct |
32 |
Correct |
4 ms |
7252 KB |
Output is correct |
33 |
Correct |
3 ms |
7252 KB |
Output is correct |
34 |
Correct |
4 ms |
7296 KB |
Output is correct |
35 |
Correct |
4 ms |
7252 KB |
Output is correct |
36 |
Correct |
4 ms |
7252 KB |
Output is correct |
37 |
Correct |
4 ms |
7252 KB |
Output is correct |
38 |
Correct |
4 ms |
7252 KB |
Output is correct |
39 |
Correct |
4 ms |
7252 KB |
Output is correct |
40 |
Correct |
6 ms |
7380 KB |
Output is correct |
41 |
Correct |
5 ms |
7508 KB |
Output is correct |
42 |
Correct |
5 ms |
7380 KB |
Output is correct |
43 |
Correct |
5 ms |
7380 KB |
Output is correct |
44 |
Correct |
5 ms |
7252 KB |
Output is correct |
45 |
Correct |
5 ms |
7380 KB |
Output is correct |
46 |
Correct |
5 ms |
7312 KB |
Output is correct |
47 |
Correct |
5 ms |
7380 KB |
Output is correct |
48 |
Correct |
20 ms |
10544 KB |
Output is correct |
49 |
Correct |
20 ms |
11044 KB |
Output is correct |
50 |
Correct |
20 ms |
11016 KB |
Output is correct |
51 |
Correct |
20 ms |
11056 KB |
Output is correct |
52 |
Correct |
21 ms |
11024 KB |
Output is correct |
53 |
Correct |
34 ms |
14772 KB |
Output is correct |
54 |
Correct |
9 ms |
7892 KB |
Output is correct |
55 |
Correct |
14 ms |
9524 KB |
Output is correct |
56 |
Correct |
4 ms |
7380 KB |
Output is correct |
57 |
Correct |
7 ms |
7892 KB |
Output is correct |
58 |
Correct |
6 ms |
7764 KB |
Output is correct |
59 |
Correct |
81 ms |
24880 KB |
Output is correct |
60 |
Correct |
123 ms |
30256 KB |
Output is correct |
61 |
Correct |
123 ms |
29920 KB |
Output is correct |
62 |
Correct |
115 ms |
30828 KB |
Output is correct |
63 |
Correct |
105 ms |
32048 KB |
Output is correct |
64 |
Correct |
114 ms |
30924 KB |
Output is correct |
65 |
Correct |
116 ms |
30276 KB |
Output is correct |
66 |
Correct |
48 ms |
16380 KB |
Output is correct |
67 |
Correct |
124 ms |
30336 KB |
Output is correct |
68 |
Correct |
70 ms |
24192 KB |
Output is correct |
69 |
Correct |
56 ms |
19464 KB |
Output is correct |
70 |
Correct |
134 ms |
32136 KB |
Output is correct |
71 |
Correct |
4 ms |
7252 KB |
Output is correct |
72 |
Correct |
4 ms |
7252 KB |
Output is correct |
73 |
Correct |
4 ms |
7340 KB |
Output is correct |
74 |
Correct |
4 ms |
7352 KB |
Output is correct |
75 |
Correct |
4 ms |
7252 KB |
Output is correct |
76 |
Correct |
3 ms |
7252 KB |
Output is correct |
77 |
Correct |
29 ms |
18224 KB |
Output is correct |
78 |
Correct |
26 ms |
18232 KB |
Output is correct |
79 |
Correct |
27 ms |
18260 KB |
Output is correct |
80 |
Correct |
27 ms |
18260 KB |
Output is correct |
81 |
Correct |
85 ms |
25124 KB |
Output is correct |
82 |
Correct |
109 ms |
30484 KB |
Output is correct |
83 |
Correct |
124 ms |
31472 KB |
Output is correct |
84 |
Correct |
154 ms |
36560 KB |
Output is correct |
85 |
Correct |
151 ms |
37444 KB |
Output is correct |
86 |
Correct |
163 ms |
36188 KB |
Output is correct |
87 |
Correct |
209 ms |
36736 KB |
Output is correct |
88 |
Correct |
4 ms |
7252 KB |
Output is correct |
89 |
Correct |
166 ms |
37488 KB |
Output is correct |
90 |
Correct |
155 ms |
36748 KB |
Output is correct |
91 |
Correct |
144 ms |
37264 KB |
Output is correct |