#include "fish.h"
#include <bits/stdc++.h>
#define ent '\n'
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 12;
vector<int> s[maxn];
vector<ll> dp[maxn], dpt[maxn], d[maxn];
vector<ll> pref[maxn], mx[maxn], suff[maxn];
vector<ll> a[maxn], mval[maxn];
long long max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
ll ans = 0;
for(int i=0;i<m;i++){
x[i]++, y[i]++;
for(int d=-1;d<=1;d++){
s[x[i] + d].push_back(y[i]);
}
}
for(int i=0;i<=n;i++){
s[i].push_back(0);
sort(s[i].begin(), s[i].end());
s[i].resize(unique(s[i].begin(), s[i].end()) - s[i].begin());
dp[i] = d[i] = pref[i] = mx[i] = suff[i] = a[i] = mval[i] = vector<ll> ((int)s[i].size(), 0);
dpt[i] = {0};
}
for(int i=0;i<m;i++){
int j = lower_bound(s[x[i]].begin(), s[x[i]].end(), y[i]) - s[x[i]].begin();
a[x[i]][j] += w[i];
}
for(int i=1;i<=n;i++){
ll sum = 0;
for(int j=0;j<s[i].size();j++){
sum += a[i][j];
pref[i][j] = sum;
}
}
for(int i=1;i<=n;i++){
dpt[i] = vector<ll> (s[i-1].size(), 0);
ll val = -1e18;
for(int j=0;j<(int)s[i].size();j++){
int x = s[i][j];
int it = upper_bound(s[i-1].begin(), s[i-1].end(), x) - s[i-1].begin();
it--;
dp[i][j] = max(mx[i-1][it] + pref[i-1][it], mval[i-1][it]);
d[i][j] = max(dp[i][j], suff[i-1][it] - pref[i][j]);
val = max(val, d[i][j]);
mval[i][j] = val;
ans = max(ans, d[i][j]);
}
for(int j=0;j<(int)s[i-1].size();j++){
int x = s[i-1][j];
int it = upper_bound(s[i].begin(), s[i].end(), x) - s[i].begin();
it--;
dpt[i][j] = d[i-1][j] + pref[i][it];
}
val = -1e18;
for(int j=0;j<(int)s[i].size();j++){
int x = s[i][j];
int it = upper_bound(s[i-1].begin(), s[i-1].end(), x) - s[i-1].begin();
it--;
val = max(val, max(dp[i][j], dpt[i][it]) - pref[i][j]);
mx[i][j] = val;
}
val = -1e18;
if(i < n){
for(int j=(int)s[i].size() - 1;j>=0;j--){
int x = s[i][j];
int it = upper_bound(s[i+1].begin(), s[i+1].end(), x) - s[i+1].begin();
it--;
val = max(val, d[i][j] + pref[i+1][it]);
suff[i][j] = val;
}
}
}
return ans;
}
Compilation message
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:36:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for(int j=0;j<s[i].size();j++){
| ~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
118 ms |
66248 KB |
Output is correct |
2 |
Correct |
135 ms |
73668 KB |
Output is correct |
3 |
Correct |
53 ms |
49516 KB |
Output is correct |
4 |
Correct |
63 ms |
49744 KB |
Output is correct |
5 |
Correct |
359 ms |
123064 KB |
Output is correct |
6 |
Correct |
297 ms |
117332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
21340 KB |
Output is correct |
2 |
Correct |
187 ms |
76596 KB |
Output is correct |
3 |
Correct |
235 ms |
85304 KB |
Output is correct |
4 |
Correct |
127 ms |
66316 KB |
Output is correct |
5 |
Correct |
128 ms |
73636 KB |
Output is correct |
6 |
Correct |
9 ms |
21340 KB |
Output is correct |
7 |
Correct |
8 ms |
21340 KB |
Output is correct |
8 |
Correct |
5 ms |
21372 KB |
Output is correct |
9 |
Correct |
7 ms |
21340 KB |
Output is correct |
10 |
Correct |
57 ms |
49636 KB |
Output is correct |
11 |
Correct |
53 ms |
49492 KB |
Output is correct |
12 |
Correct |
119 ms |
66664 KB |
Output is correct |
13 |
Correct |
166 ms |
73648 KB |
Output is correct |
14 |
Correct |
137 ms |
66368 KB |
Output is correct |
15 |
Correct |
129 ms |
66368 KB |
Output is correct |
16 |
Correct |
135 ms |
66452 KB |
Output is correct |
17 |
Correct |
186 ms |
71244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
49492 KB |
Output is correct |
2 |
Correct |
75 ms |
49628 KB |
Output is correct |
3 |
Correct |
59 ms |
48980 KB |
Output is correct |
4 |
Correct |
93 ms |
51024 KB |
Output is correct |
5 |
Correct |
83 ms |
53588 KB |
Output is correct |
6 |
Correct |
85 ms |
52908 KB |
Output is correct |
7 |
Correct |
101 ms |
53584 KB |
Output is correct |
8 |
Correct |
95 ms |
53588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
21336 KB |
Output is correct |
2 |
Correct |
9 ms |
21424 KB |
Output is correct |
3 |
Correct |
9 ms |
21340 KB |
Output is correct |
4 |
Correct |
9 ms |
21336 KB |
Output is correct |
5 |
Correct |
6 ms |
21340 KB |
Output is correct |
6 |
Correct |
7 ms |
21340 KB |
Output is correct |
7 |
Correct |
8 ms |
21340 KB |
Output is correct |
8 |
Correct |
5 ms |
21340 KB |
Output is correct |
9 |
Correct |
8 ms |
21424 KB |
Output is correct |
10 |
Correct |
11 ms |
21852 KB |
Output is correct |
11 |
Correct |
10 ms |
21596 KB |
Output is correct |
12 |
Correct |
14 ms |
21596 KB |
Output is correct |
13 |
Correct |
9 ms |
21596 KB |
Output is correct |
14 |
Correct |
10 ms |
21592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
21336 KB |
Output is correct |
2 |
Correct |
9 ms |
21424 KB |
Output is correct |
3 |
Correct |
9 ms |
21340 KB |
Output is correct |
4 |
Correct |
9 ms |
21336 KB |
Output is correct |
5 |
Correct |
6 ms |
21340 KB |
Output is correct |
6 |
Correct |
7 ms |
21340 KB |
Output is correct |
7 |
Correct |
8 ms |
21340 KB |
Output is correct |
8 |
Correct |
5 ms |
21340 KB |
Output is correct |
9 |
Correct |
8 ms |
21424 KB |
Output is correct |
10 |
Correct |
11 ms |
21852 KB |
Output is correct |
11 |
Correct |
10 ms |
21596 KB |
Output is correct |
12 |
Correct |
14 ms |
21596 KB |
Output is correct |
13 |
Correct |
9 ms |
21596 KB |
Output is correct |
14 |
Correct |
10 ms |
21592 KB |
Output is correct |
15 |
Correct |
9 ms |
21596 KB |
Output is correct |
16 |
Correct |
15 ms |
21904 KB |
Output is correct |
17 |
Correct |
32 ms |
27984 KB |
Output is correct |
18 |
Correct |
30 ms |
27236 KB |
Output is correct |
19 |
Correct |
46 ms |
27224 KB |
Output is correct |
20 |
Correct |
28 ms |
26972 KB |
Output is correct |
21 |
Correct |
29 ms |
26716 KB |
Output is correct |
22 |
Correct |
65 ms |
32084 KB |
Output is correct |
23 |
Correct |
19 ms |
23644 KB |
Output is correct |
24 |
Correct |
27 ms |
27256 KB |
Output is correct |
25 |
Correct |
10 ms |
21848 KB |
Output is correct |
26 |
Correct |
14 ms |
23380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
21336 KB |
Output is correct |
2 |
Correct |
9 ms |
21424 KB |
Output is correct |
3 |
Correct |
9 ms |
21340 KB |
Output is correct |
4 |
Correct |
9 ms |
21336 KB |
Output is correct |
5 |
Correct |
6 ms |
21340 KB |
Output is correct |
6 |
Correct |
7 ms |
21340 KB |
Output is correct |
7 |
Correct |
8 ms |
21340 KB |
Output is correct |
8 |
Correct |
5 ms |
21340 KB |
Output is correct |
9 |
Correct |
8 ms |
21424 KB |
Output is correct |
10 |
Correct |
11 ms |
21852 KB |
Output is correct |
11 |
Correct |
10 ms |
21596 KB |
Output is correct |
12 |
Correct |
14 ms |
21596 KB |
Output is correct |
13 |
Correct |
9 ms |
21596 KB |
Output is correct |
14 |
Correct |
10 ms |
21592 KB |
Output is correct |
15 |
Correct |
9 ms |
21596 KB |
Output is correct |
16 |
Correct |
15 ms |
21904 KB |
Output is correct |
17 |
Correct |
32 ms |
27984 KB |
Output is correct |
18 |
Correct |
30 ms |
27236 KB |
Output is correct |
19 |
Correct |
46 ms |
27224 KB |
Output is correct |
20 |
Correct |
28 ms |
26972 KB |
Output is correct |
21 |
Correct |
29 ms |
26716 KB |
Output is correct |
22 |
Correct |
65 ms |
32084 KB |
Output is correct |
23 |
Correct |
19 ms |
23644 KB |
Output is correct |
24 |
Correct |
27 ms |
27256 KB |
Output is correct |
25 |
Correct |
10 ms |
21848 KB |
Output is correct |
26 |
Correct |
14 ms |
23380 KB |
Output is correct |
27 |
Correct |
16 ms |
22876 KB |
Output is correct |
28 |
Correct |
114 ms |
50596 KB |
Output is correct |
29 |
Correct |
231 ms |
70012 KB |
Output is correct |
30 |
Correct |
234 ms |
94288 KB |
Output is correct |
31 |
Correct |
228 ms |
93952 KB |
Output is correct |
32 |
Correct |
161 ms |
57188 KB |
Output is correct |
33 |
Correct |
255 ms |
95568 KB |
Output is correct |
34 |
Correct |
248 ms |
95568 KB |
Output is correct |
35 |
Correct |
88 ms |
44544 KB |
Output is correct |
36 |
Correct |
223 ms |
85316 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
49492 KB |
Output is correct |
2 |
Correct |
75 ms |
49628 KB |
Output is correct |
3 |
Correct |
59 ms |
48980 KB |
Output is correct |
4 |
Correct |
93 ms |
51024 KB |
Output is correct |
5 |
Correct |
83 ms |
53588 KB |
Output is correct |
6 |
Correct |
85 ms |
52908 KB |
Output is correct |
7 |
Correct |
101 ms |
53584 KB |
Output is correct |
8 |
Correct |
95 ms |
53588 KB |
Output is correct |
9 |
Correct |
110 ms |
68948 KB |
Output is correct |
10 |
Correct |
62 ms |
40528 KB |
Output is correct |
11 |
Correct |
155 ms |
59744 KB |
Output is correct |
12 |
Correct |
11 ms |
21336 KB |
Output is correct |
13 |
Correct |
7 ms |
21592 KB |
Output is correct |
14 |
Correct |
10 ms |
21572 KB |
Output is correct |
15 |
Correct |
7 ms |
21340 KB |
Output is correct |
16 |
Correct |
9 ms |
21340 KB |
Output is correct |
17 |
Correct |
6 ms |
21340 KB |
Output is correct |
18 |
Correct |
54 ms |
49488 KB |
Output is correct |
19 |
Correct |
50 ms |
49536 KB |
Output is correct |
20 |
Correct |
56 ms |
49692 KB |
Output is correct |
21 |
Correct |
48 ms |
49572 KB |
Output is correct |
22 |
Correct |
142 ms |
66072 KB |
Output is correct |
23 |
Correct |
175 ms |
77412 KB |
Output is correct |
24 |
Correct |
192 ms |
79068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
118 ms |
66248 KB |
Output is correct |
2 |
Correct |
135 ms |
73668 KB |
Output is correct |
3 |
Correct |
53 ms |
49516 KB |
Output is correct |
4 |
Correct |
63 ms |
49744 KB |
Output is correct |
5 |
Correct |
359 ms |
123064 KB |
Output is correct |
6 |
Correct |
297 ms |
117332 KB |
Output is correct |
7 |
Correct |
6 ms |
21340 KB |
Output is correct |
8 |
Correct |
187 ms |
76596 KB |
Output is correct |
9 |
Correct |
235 ms |
85304 KB |
Output is correct |
10 |
Correct |
127 ms |
66316 KB |
Output is correct |
11 |
Correct |
128 ms |
73636 KB |
Output is correct |
12 |
Correct |
9 ms |
21340 KB |
Output is correct |
13 |
Correct |
8 ms |
21340 KB |
Output is correct |
14 |
Correct |
5 ms |
21372 KB |
Output is correct |
15 |
Correct |
7 ms |
21340 KB |
Output is correct |
16 |
Correct |
57 ms |
49636 KB |
Output is correct |
17 |
Correct |
53 ms |
49492 KB |
Output is correct |
18 |
Correct |
119 ms |
66664 KB |
Output is correct |
19 |
Correct |
166 ms |
73648 KB |
Output is correct |
20 |
Correct |
137 ms |
66368 KB |
Output is correct |
21 |
Correct |
129 ms |
66368 KB |
Output is correct |
22 |
Correct |
135 ms |
66452 KB |
Output is correct |
23 |
Correct |
186 ms |
71244 KB |
Output is correct |
24 |
Correct |
70 ms |
49492 KB |
Output is correct |
25 |
Correct |
75 ms |
49628 KB |
Output is correct |
26 |
Correct |
59 ms |
48980 KB |
Output is correct |
27 |
Correct |
93 ms |
51024 KB |
Output is correct |
28 |
Correct |
83 ms |
53588 KB |
Output is correct |
29 |
Correct |
85 ms |
52908 KB |
Output is correct |
30 |
Correct |
101 ms |
53584 KB |
Output is correct |
31 |
Correct |
95 ms |
53588 KB |
Output is correct |
32 |
Correct |
7 ms |
21336 KB |
Output is correct |
33 |
Correct |
9 ms |
21424 KB |
Output is correct |
34 |
Correct |
9 ms |
21340 KB |
Output is correct |
35 |
Correct |
9 ms |
21336 KB |
Output is correct |
36 |
Correct |
6 ms |
21340 KB |
Output is correct |
37 |
Correct |
7 ms |
21340 KB |
Output is correct |
38 |
Correct |
8 ms |
21340 KB |
Output is correct |
39 |
Correct |
5 ms |
21340 KB |
Output is correct |
40 |
Correct |
8 ms |
21424 KB |
Output is correct |
41 |
Correct |
11 ms |
21852 KB |
Output is correct |
42 |
Correct |
10 ms |
21596 KB |
Output is correct |
43 |
Correct |
14 ms |
21596 KB |
Output is correct |
44 |
Correct |
9 ms |
21596 KB |
Output is correct |
45 |
Correct |
10 ms |
21592 KB |
Output is correct |
46 |
Correct |
9 ms |
21596 KB |
Output is correct |
47 |
Correct |
15 ms |
21904 KB |
Output is correct |
48 |
Correct |
32 ms |
27984 KB |
Output is correct |
49 |
Correct |
30 ms |
27236 KB |
Output is correct |
50 |
Correct |
46 ms |
27224 KB |
Output is correct |
51 |
Correct |
28 ms |
26972 KB |
Output is correct |
52 |
Correct |
29 ms |
26716 KB |
Output is correct |
53 |
Correct |
65 ms |
32084 KB |
Output is correct |
54 |
Correct |
19 ms |
23644 KB |
Output is correct |
55 |
Correct |
27 ms |
27256 KB |
Output is correct |
56 |
Correct |
10 ms |
21848 KB |
Output is correct |
57 |
Correct |
14 ms |
23380 KB |
Output is correct |
58 |
Correct |
16 ms |
22876 KB |
Output is correct |
59 |
Correct |
114 ms |
50596 KB |
Output is correct |
60 |
Correct |
231 ms |
70012 KB |
Output is correct |
61 |
Correct |
234 ms |
94288 KB |
Output is correct |
62 |
Correct |
228 ms |
93952 KB |
Output is correct |
63 |
Correct |
161 ms |
57188 KB |
Output is correct |
64 |
Correct |
255 ms |
95568 KB |
Output is correct |
65 |
Correct |
248 ms |
95568 KB |
Output is correct |
66 |
Correct |
88 ms |
44544 KB |
Output is correct |
67 |
Correct |
223 ms |
85316 KB |
Output is correct |
68 |
Correct |
110 ms |
68948 KB |
Output is correct |
69 |
Correct |
62 ms |
40528 KB |
Output is correct |
70 |
Correct |
155 ms |
59744 KB |
Output is correct |
71 |
Correct |
11 ms |
21336 KB |
Output is correct |
72 |
Correct |
7 ms |
21592 KB |
Output is correct |
73 |
Correct |
10 ms |
21572 KB |
Output is correct |
74 |
Correct |
7 ms |
21340 KB |
Output is correct |
75 |
Correct |
9 ms |
21340 KB |
Output is correct |
76 |
Correct |
6 ms |
21340 KB |
Output is correct |
77 |
Correct |
54 ms |
49488 KB |
Output is correct |
78 |
Correct |
50 ms |
49536 KB |
Output is correct |
79 |
Correct |
56 ms |
49692 KB |
Output is correct |
80 |
Correct |
48 ms |
49572 KB |
Output is correct |
81 |
Correct |
142 ms |
66072 KB |
Output is correct |
82 |
Correct |
175 ms |
77412 KB |
Output is correct |
83 |
Correct |
192 ms |
79068 KB |
Output is correct |
84 |
Correct |
362 ms |
113076 KB |
Output is correct |
85 |
Correct |
373 ms |
114772 KB |
Output is correct |
86 |
Correct |
304 ms |
114408 KB |
Output is correct |
87 |
Correct |
299 ms |
116820 KB |
Output is correct |
88 |
Correct |
11 ms |
21340 KB |
Output is correct |
89 |
Correct |
298 ms |
116840 KB |
Output is correct |
90 |
Correct |
267 ms |
105080 KB |
Output is correct |
91 |
Correct |
226 ms |
89428 KB |
Output is correct |