#include "fish.h"
#include "bits/stdc++.h"
#include <vector>
struct CaF {
long long x, w;
};
using ll = long long;
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
using namespace std;
vector<vector<CaF>> fi(N);
for (int i = 0; i < N; ++i) {
fi[i].push_back({-1, 0});
}
for (int i = 0; i < M; ++i) {
fi[X[i]].push_back({Y[i], W[i]});
}
for (int i = 0; i < N; ++i) {
sort(fi[i].begin(), fi[i].end(), [](const CaF &l, const CaF &r) { return l.x < r.x; });
}
vector<ll> dpU(fi[0].size()), dpD(fi[0].size());
for (int i = 1; i < N; ++i) {
vector<ll> dpNU(fi[i].size()), dpND(fi[i].size()), dp0(fi[i].size());
int laP = 0;
ll su = 0;
ll beSu = 1e9;
int be = 0;
for (int j = 0; j < fi[i].size(); ++j) {
while (laP < fi[i - 1].size() && (j == fi[i].size() - 1 || fi[i - 1][laP].x < fi[i][j + 1].x)) {
su += fi[i - 1][laP].w;
if (dpU[laP] - su > dpU[be] - beSu) {
be = laP;
beSu = su;
}
laP++;
}
dpNU[j] = dpU[be] + su - beSu;
}
laP = fi[i - 1].size() - 1;
su = 0;
beSu = 0;
be = fi[i - 1].size() - 1;
for (int j = fi[i].size() - 1; j >= 0; --j) {
while (laP >= 0 && fi[i - 1][laP].x > fi[i][j].x) {
laP--;
if (dpD[laP] - su > dpD[be] - beSu) {
be = laP;
beSu = su;
}
}
dpND[j] = max(dpD[be] + su - beSu, dpNU[j]);
su += fi[i][j].w;
}
laP = 0;
su = 0;
for (int j = 0; j < fi[i - 1].size(); ++j) {
while (laP < fi[i].size() && (j == fi[i - 1].size() - 1 || fi[i - 1][j + 1].x > fi[i][laP].x)) {
su += fi[i][laP].w;
dp0[laP] = dpD[j] + su;
laP++;
}
dp0[laP - 1] = max(dpD[j] + su, dp0[laP - 1]);
}
for (int j = dp0.size() - 1; j >= 0; --j) {
dpNU[j] = max(dp0[j], dpNU[j]);
}
dpD = dpND;
dpU = dpNU;
}
return max(*max_element(dpU.begin(), dpU.end()), *max_element(dpD.begin(), dpD.end()));
}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:32:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<CaF>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for (int j = 0; j < fi[i].size(); ++j) {
| ~~^~~~~~~~~~~~~~
fish.cpp:33:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<CaF>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | while (laP < fi[i - 1].size() && (j == fi[i].size() - 1 || fi[i - 1][laP].x < fi[i][j + 1].x)) {
| ~~~~^~~~~~~~~~~~~~~~~~
fish.cpp:33:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<CaF>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | while (laP < fi[i - 1].size() && (j == fi[i].size() - 1 || fi[i - 1][laP].x < fi[i][j + 1].x)) {
| ~~^~~~~~~~~~~~~~~~~~~
fish.cpp:60:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<CaF>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for (int j = 0; j < fi[i - 1].size(); ++j) {
| ~~^~~~~~~~~~~~~~~~~~
fish.cpp:61:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<CaF>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | while (laP < fi[i].size() && (j == fi[i - 1].size() - 1 || fi[i - 1][j + 1].x > fi[i][laP].x)) {
| ~~~~^~~~~~~~~~~~~~
fish.cpp:61:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<CaF>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | while (laP < fi[i].size() && (j == fi[i - 1].size() - 1 || fi[i - 1][j + 1].x > fi[i][laP].x)) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
11108 KB |
Output is correct |
2 |
Correct |
40 ms |
13004 KB |
Output is correct |
3 |
Correct |
13 ms |
5724 KB |
Output is correct |
4 |
Correct |
12 ms |
5720 KB |
Output is correct |
5 |
Correct |
93 ms |
27944 KB |
Output is correct |
6 |
Correct |
96 ms |
28756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
54 ms |
17480 KB |
Output is correct |
3 |
Correct |
63 ms |
21004 KB |
Output is correct |
4 |
Correct |
43 ms |
10948 KB |
Output is correct |
5 |
Correct |
38 ms |
12944 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
604 KB |
Output is correct |
10 |
Correct |
12 ms |
5724 KB |
Output is correct |
11 |
Correct |
12 ms |
5724 KB |
Output is correct |
12 |
Correct |
33 ms |
12932 KB |
Output is correct |
13 |
Correct |
56 ms |
15308 KB |
Output is correct |
14 |
Correct |
32 ms |
11296 KB |
Output is correct |
15 |
Correct |
42 ms |
13300 KB |
Output is correct |
16 |
Correct |
33 ms |
11532 KB |
Output is correct |
17 |
Correct |
36 ms |
12720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
5720 KB |
Output is correct |
2 |
Correct |
11 ms |
5720 KB |
Output is correct |
3 |
Correct |
29 ms |
9048 KB |
Output is correct |
4 |
Correct |
24 ms |
8400 KB |
Output is correct |
5 |
Correct |
44 ms |
12112 KB |
Output is correct |
6 |
Correct |
38 ms |
11600 KB |
Output is correct |
7 |
Correct |
41 ms |
12132 KB |
Output is correct |
8 |
Correct |
40 ms |
12080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
10 ms |
3164 KB |
Output is correct |
18 |
Correct |
11 ms |
3780 KB |
Output is correct |
19 |
Correct |
10 ms |
3412 KB |
Output is correct |
20 |
Correct |
9 ms |
3640 KB |
Output is correct |
21 |
Correct |
10 ms |
3420 KB |
Output is correct |
22 |
Correct |
20 ms |
6748 KB |
Output is correct |
23 |
Correct |
3 ms |
860 KB |
Output is correct |
24 |
Correct |
7 ms |
2140 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
10 ms |
3164 KB |
Output is correct |
18 |
Correct |
11 ms |
3780 KB |
Output is correct |
19 |
Correct |
10 ms |
3412 KB |
Output is correct |
20 |
Correct |
9 ms |
3640 KB |
Output is correct |
21 |
Correct |
10 ms |
3420 KB |
Output is correct |
22 |
Correct |
20 ms |
6748 KB |
Output is correct |
23 |
Correct |
3 ms |
860 KB |
Output is correct |
24 |
Correct |
7 ms |
2140 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
928 KB |
Output is correct |
27 |
Correct |
1 ms |
756 KB |
Output is correct |
28 |
Correct |
47 ms |
15240 KB |
Output is correct |
29 |
Correct |
74 ms |
20304 KB |
Output is correct |
30 |
Correct |
73 ms |
19792 KB |
Output is correct |
31 |
Correct |
71 ms |
19796 KB |
Output is correct |
32 |
Correct |
63 ms |
21076 KB |
Output is correct |
33 |
Correct |
69 ms |
19688 KB |
Output is correct |
34 |
Correct |
70 ms |
19624 KB |
Output is correct |
35 |
Correct |
31 ms |
8328 KB |
Output is correct |
36 |
Correct |
77 ms |
21840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
5720 KB |
Output is correct |
2 |
Correct |
11 ms |
5720 KB |
Output is correct |
3 |
Correct |
29 ms |
9048 KB |
Output is correct |
4 |
Correct |
24 ms |
8400 KB |
Output is correct |
5 |
Correct |
44 ms |
12112 KB |
Output is correct |
6 |
Correct |
38 ms |
11600 KB |
Output is correct |
7 |
Correct |
41 ms |
12132 KB |
Output is correct |
8 |
Correct |
40 ms |
12080 KB |
Output is correct |
9 |
Correct |
43 ms |
11860 KB |
Output is correct |
10 |
Correct |
34 ms |
10064 KB |
Output is correct |
11 |
Correct |
68 ms |
19928 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
12 ms |
5724 KB |
Output is correct |
19 |
Correct |
12 ms |
5724 KB |
Output is correct |
20 |
Correct |
12 ms |
5724 KB |
Output is correct |
21 |
Correct |
12 ms |
5720 KB |
Output is correct |
22 |
Correct |
45 ms |
13384 KB |
Output is correct |
23 |
Correct |
75 ms |
19968 KB |
Output is correct |
24 |
Correct |
72 ms |
20316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
11108 KB |
Output is correct |
2 |
Correct |
40 ms |
13004 KB |
Output is correct |
3 |
Correct |
13 ms |
5724 KB |
Output is correct |
4 |
Correct |
12 ms |
5720 KB |
Output is correct |
5 |
Correct |
93 ms |
27944 KB |
Output is correct |
6 |
Correct |
96 ms |
28756 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
54 ms |
17480 KB |
Output is correct |
9 |
Correct |
63 ms |
21004 KB |
Output is correct |
10 |
Correct |
43 ms |
10948 KB |
Output is correct |
11 |
Correct |
38 ms |
12944 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Correct |
12 ms |
5724 KB |
Output is correct |
17 |
Correct |
12 ms |
5724 KB |
Output is correct |
18 |
Correct |
33 ms |
12932 KB |
Output is correct |
19 |
Correct |
56 ms |
15308 KB |
Output is correct |
20 |
Correct |
32 ms |
11296 KB |
Output is correct |
21 |
Correct |
42 ms |
13300 KB |
Output is correct |
22 |
Correct |
33 ms |
11532 KB |
Output is correct |
23 |
Correct |
36 ms |
12720 KB |
Output is correct |
24 |
Correct |
12 ms |
5720 KB |
Output is correct |
25 |
Correct |
11 ms |
5720 KB |
Output is correct |
26 |
Correct |
29 ms |
9048 KB |
Output is correct |
27 |
Correct |
24 ms |
8400 KB |
Output is correct |
28 |
Correct |
44 ms |
12112 KB |
Output is correct |
29 |
Correct |
38 ms |
11600 KB |
Output is correct |
30 |
Correct |
41 ms |
12132 KB |
Output is correct |
31 |
Correct |
40 ms |
12080 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
344 KB |
Output is correct |
41 |
Correct |
1 ms |
604 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
1 ms |
344 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
10 ms |
3164 KB |
Output is correct |
49 |
Correct |
11 ms |
3780 KB |
Output is correct |
50 |
Correct |
10 ms |
3412 KB |
Output is correct |
51 |
Correct |
9 ms |
3640 KB |
Output is correct |
52 |
Correct |
10 ms |
3420 KB |
Output is correct |
53 |
Correct |
20 ms |
6748 KB |
Output is correct |
54 |
Correct |
3 ms |
860 KB |
Output is correct |
55 |
Correct |
7 ms |
2140 KB |
Output is correct |
56 |
Correct |
1 ms |
348 KB |
Output is correct |
57 |
Correct |
2 ms |
928 KB |
Output is correct |
58 |
Correct |
1 ms |
756 KB |
Output is correct |
59 |
Correct |
47 ms |
15240 KB |
Output is correct |
60 |
Correct |
74 ms |
20304 KB |
Output is correct |
61 |
Correct |
73 ms |
19792 KB |
Output is correct |
62 |
Correct |
71 ms |
19796 KB |
Output is correct |
63 |
Correct |
63 ms |
21076 KB |
Output is correct |
64 |
Correct |
69 ms |
19688 KB |
Output is correct |
65 |
Correct |
70 ms |
19624 KB |
Output is correct |
66 |
Correct |
31 ms |
8328 KB |
Output is correct |
67 |
Correct |
77 ms |
21840 KB |
Output is correct |
68 |
Correct |
43 ms |
11860 KB |
Output is correct |
69 |
Correct |
34 ms |
10064 KB |
Output is correct |
70 |
Correct |
68 ms |
19928 KB |
Output is correct |
71 |
Correct |
0 ms |
344 KB |
Output is correct |
72 |
Correct |
0 ms |
348 KB |
Output is correct |
73 |
Correct |
0 ms |
348 KB |
Output is correct |
74 |
Correct |
0 ms |
348 KB |
Output is correct |
75 |
Correct |
0 ms |
348 KB |
Output is correct |
76 |
Correct |
0 ms |
348 KB |
Output is correct |
77 |
Correct |
12 ms |
5724 KB |
Output is correct |
78 |
Correct |
12 ms |
5724 KB |
Output is correct |
79 |
Correct |
12 ms |
5724 KB |
Output is correct |
80 |
Correct |
12 ms |
5720 KB |
Output is correct |
81 |
Correct |
45 ms |
13384 KB |
Output is correct |
82 |
Correct |
75 ms |
19968 KB |
Output is correct |
83 |
Correct |
72 ms |
20316 KB |
Output is correct |
84 |
Correct |
96 ms |
24212 KB |
Output is correct |
85 |
Correct |
96 ms |
24420 KB |
Output is correct |
86 |
Correct |
111 ms |
26192 KB |
Output is correct |
87 |
Correct |
98 ms |
26724 KB |
Output is correct |
88 |
Correct |
0 ms |
348 KB |
Output is correct |
89 |
Correct |
103 ms |
26900 KB |
Output is correct |
90 |
Correct |
100 ms |
25944 KB |
Output is correct |
91 |
Correct |
77 ms |
25936 KB |
Output is correct |