#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());
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;
}
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)) {
| ~~^~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
10944 KB |
Output is correct |
2 |
Correct |
35 ms |
12984 KB |
Output is correct |
3 |
Correct |
10 ms |
5724 KB |
Output is correct |
4 |
Correct |
10 ms |
5672 KB |
Output is correct |
5 |
Correct |
92 ms |
27180 KB |
Output is correct |
6 |
Correct |
88 ms |
28752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
58 ms |
16852 KB |
Output is correct |
3 |
Correct |
63 ms |
20148 KB |
Output is correct |
4 |
Correct |
30 ms |
10944 KB |
Output is correct |
5 |
Correct |
35 ms |
13004 KB |
Output is correct |
6 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
10 |
Correct |
13 ms |
5976 KB |
Output is correct |
11 |
Correct |
10 ms |
5724 KB |
Output is correct |
12 |
Correct |
30 ms |
12416 KB |
Output is correct |
13 |
Correct |
37 ms |
14540 KB |
Output is correct |
14 |
Correct |
30 ms |
11044 KB |
Output is correct |
15 |
Correct |
34 ms |
12992 KB |
Output is correct |
16 |
Correct |
31 ms |
11016 KB |
Output is correct |
17 |
Correct |
33 ms |
12220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
5980 KB |
Output is correct |
2 |
Correct |
10 ms |
5724 KB |
Output is correct |
3 |
Incorrect |
24 ms |
8792 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '3655092595137' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 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 |
344 KB |
Output is correct |
9 |
Incorrect |
0 ms |
440 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '7818664569' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 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 |
344 KB |
Output is correct |
9 |
Incorrect |
0 ms |
440 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '7818664569' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 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 |
344 KB |
Output is correct |
9 |
Incorrect |
0 ms |
440 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '7818664569' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
5980 KB |
Output is correct |
2 |
Correct |
10 ms |
5724 KB |
Output is correct |
3 |
Incorrect |
24 ms |
8792 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '3655092595137' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
10944 KB |
Output is correct |
2 |
Correct |
35 ms |
12984 KB |
Output is correct |
3 |
Correct |
10 ms |
5724 KB |
Output is correct |
4 |
Correct |
10 ms |
5672 KB |
Output is correct |
5 |
Correct |
92 ms |
27180 KB |
Output is correct |
6 |
Correct |
88 ms |
28752 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
58 ms |
16852 KB |
Output is correct |
9 |
Correct |
63 ms |
20148 KB |
Output is correct |
10 |
Correct |
30 ms |
10944 KB |
Output is correct |
11 |
Correct |
35 ms |
13004 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 |
13 ms |
5976 KB |
Output is correct |
17 |
Correct |
10 ms |
5724 KB |
Output is correct |
18 |
Correct |
30 ms |
12416 KB |
Output is correct |
19 |
Correct |
37 ms |
14540 KB |
Output is correct |
20 |
Correct |
30 ms |
11044 KB |
Output is correct |
21 |
Correct |
34 ms |
12992 KB |
Output is correct |
22 |
Correct |
31 ms |
11016 KB |
Output is correct |
23 |
Correct |
33 ms |
12220 KB |
Output is correct |
24 |
Correct |
12 ms |
5980 KB |
Output is correct |
25 |
Correct |
10 ms |
5724 KB |
Output is correct |
26 |
Incorrect |
24 ms |
8792 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '3655092595137' |
27 |
Halted |
0 ms |
0 KB |
- |