#include <bits/stdc++.h>
#include "fish.h"
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<pii, ll> tri;
const int MAXN = 100010;
const ll INF = 1e18;
vector<pii> HW[MAXN];
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
vector<tri> P;
for(int i=0 ; i<M ; i++){
P.emplace_back(pii(X[i], Y[i]), W[i]);
}
sort(P.begin(), P.end());
for(int i=0 ; i<M ; i++){
HW[P[i].first.first].emplace_back(P[i].first.second, P[i].second);
}
vector<ll> U(HW[0].size(), 0), D(HW[0].size(), 0);
ll T = 0, S = 0;
for(int j=0 ; j<HW[0].size() ; j++){
S += HW[0][j].second;
D[j] = S;
}
for(int i=1 ; i<N ; i++){
vector<ll> new_U(HW[i].size(), 0), new_D(HW[i].size(), 0);
ll S = 0, ma = -INF;
for(int j=HW[i].size()-1 ; j>=0 ; j--){
S += HW[i][j].second;
new_U[j] = T + S;
}
S = 0;
for(int j=HW[i].size()-1 ; j>=0 ; j--){
auto [x, w] = HW[i][j];
int idx = lower_bound(HW[i-1].begin(), HW[i-1].end(), pii(x+1, 0)) - HW[i-1].begin();
if(idx < U.size()){
ma = max(ma, U[idx] - S);
new_U[j] = max(new_U[j], ma + (S + w));
}
S += w;
}
S = 0, ma = -INF;
for(int j=0 ; j<HW[i].size() ; j++){
S += HW[i][j].second;
if(U.size()){
new_D[j] = U[0] + S;
}
}
S = 0;
for(int j=0 ; j<HW[i].size() ; j++){
auto [x, w] = HW[i][j];
int idx = lower_bound(HW[i-1].begin(), HW[i-1].end(), pii(x, 0)) - HW[i-1].begin() - 1;
if(idx >= 0 && idx < U.size()){
ma = max(ma, D[idx] - S);
new_D[j] = max(new_D[j], ma + (S + w));
}
S += w;
}
if(U.size()){
T = max(T, U[0]);
T = max(T, D[D.size()-1]);
}
U = new_U;
D = new_D;
}
if(U.size()){
T = max(T, U[0]);
}
return T;
}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:24:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for(int j=0 ; j<HW[0].size() ; j++){
| ~^~~~~~~~~~~~~
fish.cpp:40:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | if(idx < U.size()){
| ~~~~^~~~~~~~~~
fish.cpp:47:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(int j=0 ; j<HW[i].size() ; j++){
| ~^~~~~~~~~~~~~
fish.cpp:54:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for(int j=0 ; j<HW[i].size() ; j++){
| ~^~~~~~~~~~~~~
fish.cpp:57:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | if(idx >= 0 && idx < U.size()){
| ~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
9720 KB |
Output is correct |
2 |
Correct |
64 ms |
10932 KB |
Output is correct |
3 |
Correct |
4 ms |
2644 KB |
Output is correct |
4 |
Correct |
5 ms |
2644 KB |
Output is correct |
5 |
Correct |
160 ms |
25456 KB |
Output is correct |
6 |
Correct |
219 ms |
23676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
98 ms |
15436 KB |
Output is correct |
3 |
Correct |
132 ms |
18736 KB |
Output is correct |
4 |
Correct |
43 ms |
9724 KB |
Output is correct |
5 |
Correct |
63 ms |
10948 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2640 KB |
Output is correct |
8 |
Correct |
2 ms |
2644 KB |
Output is correct |
9 |
Correct |
2 ms |
2644 KB |
Output is correct |
10 |
Correct |
4 ms |
2644 KB |
Output is correct |
11 |
Correct |
5 ms |
2644 KB |
Output is correct |
12 |
Correct |
44 ms |
10248 KB |
Output is correct |
13 |
Correct |
65 ms |
11996 KB |
Output is correct |
14 |
Correct |
42 ms |
9084 KB |
Output is correct |
15 |
Correct |
62 ms |
10732 KB |
Output is correct |
16 |
Correct |
43 ms |
9076 KB |
Output is correct |
17 |
Correct |
68 ms |
9948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2688 KB |
Output is correct |
2 |
Correct |
5 ms |
2644 KB |
Output is correct |
3 |
Correct |
30 ms |
6756 KB |
Output is correct |
4 |
Correct |
31 ms |
5368 KB |
Output is correct |
5 |
Correct |
72 ms |
10420 KB |
Output is correct |
6 |
Correct |
60 ms |
10364 KB |
Output is correct |
7 |
Correct |
60 ms |
10468 KB |
Output is correct |
8 |
Correct |
71 ms |
10424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
1 ms |
2644 KB |
Output is correct |
9 |
Correct |
2 ms |
2644 KB |
Output is correct |
10 |
Correct |
3 ms |
2772 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
3 ms |
2644 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
1 ms |
2644 KB |
Output is correct |
9 |
Correct |
2 ms |
2644 KB |
Output is correct |
10 |
Correct |
3 ms |
2772 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
3 ms |
2644 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2576 KB |
Output is correct |
16 |
Correct |
4 ms |
2772 KB |
Output is correct |
17 |
Correct |
23 ms |
5488 KB |
Output is correct |
18 |
Correct |
23 ms |
6124 KB |
Output is correct |
19 |
Correct |
25 ms |
5908 KB |
Output is correct |
20 |
Correct |
24 ms |
5952 KB |
Output is correct |
21 |
Correct |
30 ms |
5928 KB |
Output is correct |
22 |
Correct |
57 ms |
9196 KB |
Output is correct |
23 |
Correct |
5 ms |
3348 KB |
Output is correct |
24 |
Correct |
15 ms |
4656 KB |
Output is correct |
25 |
Correct |
2 ms |
2644 KB |
Output is correct |
26 |
Correct |
6 ms |
3352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
2 ms |
2644 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
1 ms |
2644 KB |
Output is correct |
9 |
Correct |
2 ms |
2644 KB |
Output is correct |
10 |
Correct |
3 ms |
2772 KB |
Output is correct |
11 |
Correct |
2 ms |
2644 KB |
Output is correct |
12 |
Correct |
3 ms |
2644 KB |
Output is correct |
13 |
Correct |
2 ms |
2644 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2576 KB |
Output is correct |
16 |
Correct |
4 ms |
2772 KB |
Output is correct |
17 |
Correct |
23 ms |
5488 KB |
Output is correct |
18 |
Correct |
23 ms |
6124 KB |
Output is correct |
19 |
Correct |
25 ms |
5908 KB |
Output is correct |
20 |
Correct |
24 ms |
5952 KB |
Output is correct |
21 |
Correct |
30 ms |
5928 KB |
Output is correct |
22 |
Correct |
57 ms |
9196 KB |
Output is correct |
23 |
Correct |
5 ms |
3348 KB |
Output is correct |
24 |
Correct |
15 ms |
4656 KB |
Output is correct |
25 |
Correct |
2 ms |
2644 KB |
Output is correct |
26 |
Correct |
6 ms |
3352 KB |
Output is correct |
27 |
Correct |
3 ms |
2772 KB |
Output is correct |
28 |
Correct |
120 ms |
17560 KB |
Output is correct |
29 |
Correct |
164 ms |
22136 KB |
Output is correct |
30 |
Correct |
154 ms |
22776 KB |
Output is correct |
31 |
Correct |
187 ms |
22764 KB |
Output is correct |
32 |
Correct |
195 ms |
23664 KB |
Output is correct |
33 |
Correct |
161 ms |
22772 KB |
Output is correct |
34 |
Correct |
168 ms |
22752 KB |
Output is correct |
35 |
Correct |
77 ms |
10792 KB |
Output is correct |
36 |
Correct |
157 ms |
24172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2688 KB |
Output is correct |
2 |
Correct |
5 ms |
2644 KB |
Output is correct |
3 |
Correct |
30 ms |
6756 KB |
Output is correct |
4 |
Correct |
31 ms |
5368 KB |
Output is correct |
5 |
Correct |
72 ms |
10420 KB |
Output is correct |
6 |
Correct |
60 ms |
10364 KB |
Output is correct |
7 |
Correct |
60 ms |
10468 KB |
Output is correct |
8 |
Correct |
71 ms |
10424 KB |
Output is correct |
9 |
Correct |
68 ms |
10468 KB |
Output is correct |
10 |
Correct |
51 ms |
9656 KB |
Output is correct |
11 |
Correct |
99 ms |
16752 KB |
Output is correct |
12 |
Correct |
2 ms |
2644 KB |
Output is correct |
13 |
Correct |
1 ms |
2644 KB |
Output is correct |
14 |
Correct |
1 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2644 KB |
Output is correct |
16 |
Correct |
2 ms |
2644 KB |
Output is correct |
17 |
Correct |
1 ms |
2644 KB |
Output is correct |
18 |
Correct |
2 ms |
2644 KB |
Output is correct |
19 |
Correct |
3 ms |
2644 KB |
Output is correct |
20 |
Correct |
3 ms |
2644 KB |
Output is correct |
21 |
Correct |
4 ms |
2644 KB |
Output is correct |
22 |
Correct |
62 ms |
9944 KB |
Output is correct |
23 |
Correct |
109 ms |
16664 KB |
Output is correct |
24 |
Correct |
99 ms |
16728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
9720 KB |
Output is correct |
2 |
Correct |
64 ms |
10932 KB |
Output is correct |
3 |
Correct |
4 ms |
2644 KB |
Output is correct |
4 |
Correct |
5 ms |
2644 KB |
Output is correct |
5 |
Correct |
160 ms |
25456 KB |
Output is correct |
6 |
Correct |
219 ms |
23676 KB |
Output is correct |
7 |
Correct |
2 ms |
2644 KB |
Output is correct |
8 |
Correct |
98 ms |
15436 KB |
Output is correct |
9 |
Correct |
132 ms |
18736 KB |
Output is correct |
10 |
Correct |
43 ms |
9724 KB |
Output is correct |
11 |
Correct |
63 ms |
10948 KB |
Output is correct |
12 |
Correct |
2 ms |
2644 KB |
Output is correct |
13 |
Correct |
2 ms |
2640 KB |
Output is correct |
14 |
Correct |
2 ms |
2644 KB |
Output is correct |
15 |
Correct |
2 ms |
2644 KB |
Output is correct |
16 |
Correct |
4 ms |
2644 KB |
Output is correct |
17 |
Correct |
5 ms |
2644 KB |
Output is correct |
18 |
Correct |
44 ms |
10248 KB |
Output is correct |
19 |
Correct |
65 ms |
11996 KB |
Output is correct |
20 |
Correct |
42 ms |
9084 KB |
Output is correct |
21 |
Correct |
62 ms |
10732 KB |
Output is correct |
22 |
Correct |
43 ms |
9076 KB |
Output is correct |
23 |
Correct |
68 ms |
9948 KB |
Output is correct |
24 |
Correct |
5 ms |
2688 KB |
Output is correct |
25 |
Correct |
5 ms |
2644 KB |
Output is correct |
26 |
Correct |
30 ms |
6756 KB |
Output is correct |
27 |
Correct |
31 ms |
5368 KB |
Output is correct |
28 |
Correct |
72 ms |
10420 KB |
Output is correct |
29 |
Correct |
60 ms |
10364 KB |
Output is correct |
30 |
Correct |
60 ms |
10468 KB |
Output is correct |
31 |
Correct |
71 ms |
10424 KB |
Output is correct |
32 |
Correct |
2 ms |
2644 KB |
Output is correct |
33 |
Correct |
2 ms |
2644 KB |
Output is correct |
34 |
Correct |
1 ms |
2644 KB |
Output is correct |
35 |
Correct |
2 ms |
2644 KB |
Output is correct |
36 |
Correct |
2 ms |
2644 KB |
Output is correct |
37 |
Correct |
2 ms |
2644 KB |
Output is correct |
38 |
Correct |
2 ms |
2644 KB |
Output is correct |
39 |
Correct |
1 ms |
2644 KB |
Output is correct |
40 |
Correct |
2 ms |
2644 KB |
Output is correct |
41 |
Correct |
3 ms |
2772 KB |
Output is correct |
42 |
Correct |
2 ms |
2644 KB |
Output is correct |
43 |
Correct |
3 ms |
2644 KB |
Output is correct |
44 |
Correct |
2 ms |
2644 KB |
Output is correct |
45 |
Correct |
2 ms |
2644 KB |
Output is correct |
46 |
Correct |
2 ms |
2576 KB |
Output is correct |
47 |
Correct |
4 ms |
2772 KB |
Output is correct |
48 |
Correct |
23 ms |
5488 KB |
Output is correct |
49 |
Correct |
23 ms |
6124 KB |
Output is correct |
50 |
Correct |
25 ms |
5908 KB |
Output is correct |
51 |
Correct |
24 ms |
5952 KB |
Output is correct |
52 |
Correct |
30 ms |
5928 KB |
Output is correct |
53 |
Correct |
57 ms |
9196 KB |
Output is correct |
54 |
Correct |
5 ms |
3348 KB |
Output is correct |
55 |
Correct |
15 ms |
4656 KB |
Output is correct |
56 |
Correct |
2 ms |
2644 KB |
Output is correct |
57 |
Correct |
6 ms |
3352 KB |
Output is correct |
58 |
Correct |
3 ms |
2772 KB |
Output is correct |
59 |
Correct |
120 ms |
17560 KB |
Output is correct |
60 |
Correct |
164 ms |
22136 KB |
Output is correct |
61 |
Correct |
154 ms |
22776 KB |
Output is correct |
62 |
Correct |
187 ms |
22764 KB |
Output is correct |
63 |
Correct |
195 ms |
23664 KB |
Output is correct |
64 |
Correct |
161 ms |
22772 KB |
Output is correct |
65 |
Correct |
168 ms |
22752 KB |
Output is correct |
66 |
Correct |
77 ms |
10792 KB |
Output is correct |
67 |
Correct |
157 ms |
24172 KB |
Output is correct |
68 |
Correct |
68 ms |
10468 KB |
Output is correct |
69 |
Correct |
51 ms |
9656 KB |
Output is correct |
70 |
Correct |
99 ms |
16752 KB |
Output is correct |
71 |
Correct |
2 ms |
2644 KB |
Output is correct |
72 |
Correct |
1 ms |
2644 KB |
Output is correct |
73 |
Correct |
1 ms |
2644 KB |
Output is correct |
74 |
Correct |
2 ms |
2644 KB |
Output is correct |
75 |
Correct |
2 ms |
2644 KB |
Output is correct |
76 |
Correct |
1 ms |
2644 KB |
Output is correct |
77 |
Correct |
2 ms |
2644 KB |
Output is correct |
78 |
Correct |
3 ms |
2644 KB |
Output is correct |
79 |
Correct |
3 ms |
2644 KB |
Output is correct |
80 |
Correct |
4 ms |
2644 KB |
Output is correct |
81 |
Correct |
62 ms |
9944 KB |
Output is correct |
82 |
Correct |
109 ms |
16664 KB |
Output is correct |
83 |
Correct |
99 ms |
16728 KB |
Output is correct |
84 |
Correct |
178 ms |
22496 KB |
Output is correct |
85 |
Correct |
193 ms |
22624 KB |
Output is correct |
86 |
Correct |
160 ms |
23728 KB |
Output is correct |
87 |
Correct |
214 ms |
23916 KB |
Output is correct |
88 |
Correct |
2 ms |
2644 KB |
Output is correct |
89 |
Correct |
206 ms |
23868 KB |
Output is correct |
90 |
Correct |
185 ms |
23712 KB |
Output is correct |
91 |
Correct |
156 ms |
23524 KB |
Output is correct |