#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define all(x) x.begin(), x.end()
using ll = long long;
#define pi pair<ll,ll>
#define f first
#define s second
const int N=100005;
vector<ll> pr[N];
vector<pi> f[N];
ll sum(int i, int j) {
int l=0, r=f[i].size();
while (l<r) {
int m=(l+r+1)>>1;
if (f[i][m-1].f>j) r=m-1;
else l=m;
}
return pr[i][r];
}
vector<pi> dp[N], dp2[N], dp3[N];
vector<ll> prmx[N], prmx2[N], sfmx[N];
ll prmxquery(int i, int j) {
return prmx[i].back();
}
ll prmx2query(int i, int j) {
int l=0, r=dp3[i].size();
while (l<r) {
int m=(l+r+1)>>1;
if (dp3[i][m-1].f >= j) r=m-1;
else l=m;
}
return prmx2[i][r];
}
ll sfmxquery(int i, int j) {
return sfmx[i][0];
}
ll max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
forn(i,m) {
f[x[i]+1].pb({y[i]+1,w[i]});
}
for(int i=1;i<=n;++i) {
sort(all(f[i]));
f[i].pb({n+1,0});
pr[i]={0};
forn(j,f[i].size()) pr[i].pb(pr[i].back()+f[i][j].s);
}
dp[0].pb({0,0});
dp[0].pb({n,0});
pr[0]={0,0,0};
dp2[0]=dp3[0]=dp[0];
prmx[0]={0,0};
prmx2[0]=sfmx[0]=prmx[0];
pr[n+1]={0,0,0};
for(int i=1; i<=n; ++i) {
if (f[i][0].f!=1) {
int j=0;
ll d=0;
if (i>=2) {
d=max(d,prmxquery(i-2,j)+sum(i-1,j));
d=max(d,sfmxquery(i-2,j));
}
d=max(d,prmx2query(i-1,j)+sum(i-1,j));
d=max(d,prmxquery(i-1,j));
ll d3=d;
d=max(d,sfmxquery(i-1,j)-sum(i,j));
ll d2=d+sum(i+1,j);
dp[i].pb({j,d});
dp2[i].pb({j,d2});
dp3[i].pb({j,d3});
}
for(auto&x:f[i]) {
int j=x.f-1;
ll d=0;
if (i>=2) {
d=max(d,prmxquery(i-2,j)+sum(i-1,j));
d=max(d,sfmxquery(i-2,j));
}
d=max(d,prmx2query(i-1,j)+sum(i-1,j));
d=max(d,prmxquery(i-1,j));
ll d3=d;
d=max(d,sfmxquery(i-1,j)-sum(i,j));
ll d2=d+sum(i+1,j);
dp[i].pb({j,d});
dp2[i].pb({j,d2});
dp3[i].pb({j,d3});
}
prmx[i]={0};
prmx2[i]=sfmx[i]=prmx[i];
for (int j=0; j<dp[i].size(); ++j) {
prmx[i].pb(max(prmx[i].back(),dp[i][j].s));
prmx2[i].pb(max(prmx2[i].back(),dp3[i][j].s-sum(i,dp3[i][j].f)));
}
reverse(all(dp2[i]));
for (int j=0; j<dp2[i].size(); ++j) {
sfmx[i].pb(max(sfmx[i].back(),dp2[i][j].s));
}
reverse(all(dp2[i]));
reverse(all(sfmx[i]));
}
ll ans=0;
for(auto&x:dp[n]) ans=max(ans,x.s);
return ans;
return prmx[n].back();
}
Compilation message
fish.cpp: In function 'll max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:4:32: 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]
4 | #define forn(i,n) for(int i=0;i<n;++i)
......
55 | forn(j,f[i].size()) pr[i].pb(pr[i].back()+f[i][j].s);
| ~~~~~~~~~~~~~
fish.cpp:55:5: note: in expansion of macro 'forn'
55 | forn(j,f[i].size()) pr[i].pb(pr[i].back()+f[i][j].s);
| ^~~~
fish.cpp:108: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]
108 | for (int j=0; j<dp[i].size(); ++j) {
| ~^~~~~~~~~~~~~
fish.cpp:114: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]
114 | for (int j=0; j<dp2[i].size(); ++j) {
| ~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
133 ms |
59576 KB |
Output is correct |
2 |
Correct |
152 ms |
65200 KB |
Output is correct |
3 |
Correct |
77 ms |
53476 KB |
Output is correct |
4 |
Correct |
93 ms |
53404 KB |
Output is correct |
5 |
Correct |
263 ms |
88880 KB |
Output is correct |
6 |
Correct |
350 ms |
101576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
18968 KB |
Output is correct |
2 |
Correct |
201 ms |
69468 KB |
Output is correct |
3 |
Correct |
214 ms |
77224 KB |
Output is correct |
4 |
Correct |
129 ms |
59572 KB |
Output is correct |
5 |
Correct |
143 ms |
65308 KB |
Output is correct |
6 |
Correct |
9 ms |
19028 KB |
Output is correct |
7 |
Correct |
9 ms |
19028 KB |
Output is correct |
8 |
Correct |
8 ms |
19028 KB |
Output is correct |
9 |
Correct |
9 ms |
19028 KB |
Output is correct |
10 |
Correct |
98 ms |
53408 KB |
Output is correct |
11 |
Correct |
78 ms |
53484 KB |
Output is correct |
12 |
Correct |
137 ms |
59612 KB |
Output is correct |
13 |
Correct |
147 ms |
65284 KB |
Output is correct |
14 |
Correct |
152 ms |
59844 KB |
Output is correct |
15 |
Correct |
156 ms |
64392 KB |
Output is correct |
16 |
Correct |
133 ms |
59852 KB |
Output is correct |
17 |
Correct |
149 ms |
64244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
53516 KB |
Output is correct |
2 |
Correct |
79 ms |
53436 KB |
Output is correct |
3 |
Correct |
111 ms |
52912 KB |
Output is correct |
4 |
Correct |
113 ms |
55592 KB |
Output is correct |
5 |
Correct |
150 ms |
59820 KB |
Output is correct |
6 |
Correct |
133 ms |
59824 KB |
Output is correct |
7 |
Correct |
122 ms |
59804 KB |
Output is correct |
8 |
Correct |
119 ms |
59816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
19028 KB |
Output is correct |
2 |
Correct |
9 ms |
19016 KB |
Output is correct |
3 |
Correct |
9 ms |
19088 KB |
Output is correct |
4 |
Correct |
9 ms |
19028 KB |
Output is correct |
5 |
Correct |
9 ms |
19068 KB |
Output is correct |
6 |
Correct |
11 ms |
19028 KB |
Output is correct |
7 |
Correct |
8 ms |
19028 KB |
Output is correct |
8 |
Correct |
12 ms |
19028 KB |
Output is correct |
9 |
Correct |
9 ms |
19236 KB |
Output is correct |
10 |
Correct |
13 ms |
19640 KB |
Output is correct |
11 |
Correct |
8 ms |
19184 KB |
Output is correct |
12 |
Correct |
8 ms |
19284 KB |
Output is correct |
13 |
Correct |
8 ms |
19028 KB |
Output is correct |
14 |
Correct |
11 ms |
19272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
19028 KB |
Output is correct |
2 |
Correct |
9 ms |
19016 KB |
Output is correct |
3 |
Correct |
9 ms |
19088 KB |
Output is correct |
4 |
Correct |
9 ms |
19028 KB |
Output is correct |
5 |
Correct |
9 ms |
19068 KB |
Output is correct |
6 |
Correct |
11 ms |
19028 KB |
Output is correct |
7 |
Correct |
8 ms |
19028 KB |
Output is correct |
8 |
Correct |
12 ms |
19028 KB |
Output is correct |
9 |
Correct |
9 ms |
19236 KB |
Output is correct |
10 |
Correct |
13 ms |
19640 KB |
Output is correct |
11 |
Correct |
8 ms |
19184 KB |
Output is correct |
12 |
Correct |
8 ms |
19284 KB |
Output is correct |
13 |
Correct |
8 ms |
19028 KB |
Output is correct |
14 |
Correct |
11 ms |
19272 KB |
Output is correct |
15 |
Correct |
12 ms |
19152 KB |
Output is correct |
16 |
Correct |
10 ms |
19440 KB |
Output is correct |
17 |
Correct |
31 ms |
24764 KB |
Output is correct |
18 |
Correct |
31 ms |
28200 KB |
Output is correct |
19 |
Correct |
31 ms |
27392 KB |
Output is correct |
20 |
Correct |
31 ms |
27444 KB |
Output is correct |
21 |
Correct |
29 ms |
27424 KB |
Output is correct |
22 |
Correct |
52 ms |
35772 KB |
Output is correct |
23 |
Correct |
14 ms |
20604 KB |
Output is correct |
24 |
Correct |
24 ms |
23508 KB |
Output is correct |
25 |
Correct |
10 ms |
19284 KB |
Output is correct |
26 |
Correct |
13 ms |
20436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
19028 KB |
Output is correct |
2 |
Correct |
9 ms |
19016 KB |
Output is correct |
3 |
Correct |
9 ms |
19088 KB |
Output is correct |
4 |
Correct |
9 ms |
19028 KB |
Output is correct |
5 |
Correct |
9 ms |
19068 KB |
Output is correct |
6 |
Correct |
11 ms |
19028 KB |
Output is correct |
7 |
Correct |
8 ms |
19028 KB |
Output is correct |
8 |
Correct |
12 ms |
19028 KB |
Output is correct |
9 |
Correct |
9 ms |
19236 KB |
Output is correct |
10 |
Correct |
13 ms |
19640 KB |
Output is correct |
11 |
Correct |
8 ms |
19184 KB |
Output is correct |
12 |
Correct |
8 ms |
19284 KB |
Output is correct |
13 |
Correct |
8 ms |
19028 KB |
Output is correct |
14 |
Correct |
11 ms |
19272 KB |
Output is correct |
15 |
Correct |
12 ms |
19152 KB |
Output is correct |
16 |
Correct |
10 ms |
19440 KB |
Output is correct |
17 |
Correct |
31 ms |
24764 KB |
Output is correct |
18 |
Correct |
31 ms |
28200 KB |
Output is correct |
19 |
Correct |
31 ms |
27392 KB |
Output is correct |
20 |
Correct |
31 ms |
27444 KB |
Output is correct |
21 |
Correct |
29 ms |
27424 KB |
Output is correct |
22 |
Correct |
52 ms |
35772 KB |
Output is correct |
23 |
Correct |
14 ms |
20604 KB |
Output is correct |
24 |
Correct |
24 ms |
23508 KB |
Output is correct |
25 |
Correct |
10 ms |
19284 KB |
Output is correct |
26 |
Correct |
13 ms |
20436 KB |
Output is correct |
27 |
Correct |
12 ms |
20564 KB |
Output is correct |
28 |
Correct |
123 ms |
56568 KB |
Output is correct |
29 |
Correct |
184 ms |
64716 KB |
Output is correct |
30 |
Correct |
157 ms |
62796 KB |
Output is correct |
31 |
Correct |
153 ms |
62756 KB |
Output is correct |
32 |
Correct |
163 ms |
74200 KB |
Output is correct |
33 |
Correct |
163 ms |
62812 KB |
Output is correct |
34 |
Correct |
152 ms |
62820 KB |
Output is correct |
35 |
Correct |
66 ms |
38892 KB |
Output is correct |
36 |
Correct |
165 ms |
72388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
53516 KB |
Output is correct |
2 |
Correct |
79 ms |
53436 KB |
Output is correct |
3 |
Correct |
111 ms |
52912 KB |
Output is correct |
4 |
Correct |
113 ms |
55592 KB |
Output is correct |
5 |
Correct |
150 ms |
59820 KB |
Output is correct |
6 |
Correct |
133 ms |
59824 KB |
Output is correct |
7 |
Correct |
122 ms |
59804 KB |
Output is correct |
8 |
Correct |
119 ms |
59816 KB |
Output is correct |
9 |
Correct |
134 ms |
69280 KB |
Output is correct |
10 |
Correct |
84 ms |
46592 KB |
Output is correct |
11 |
Correct |
167 ms |
74188 KB |
Output is correct |
12 |
Correct |
9 ms |
19032 KB |
Output is correct |
13 |
Correct |
12 ms |
19028 KB |
Output is correct |
14 |
Correct |
9 ms |
19096 KB |
Output is correct |
15 |
Correct |
8 ms |
19028 KB |
Output is correct |
16 |
Correct |
9 ms |
19028 KB |
Output is correct |
17 |
Correct |
11 ms |
19028 KB |
Output is correct |
18 |
Correct |
75 ms |
53508 KB |
Output is correct |
19 |
Correct |
77 ms |
53508 KB |
Output is correct |
20 |
Correct |
76 ms |
53508 KB |
Output is correct |
21 |
Correct |
78 ms |
53480 KB |
Output is correct |
22 |
Correct |
164 ms |
68260 KB |
Output is correct |
23 |
Correct |
205 ms |
82964 KB |
Output is correct |
24 |
Correct |
187 ms |
83540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
133 ms |
59576 KB |
Output is correct |
2 |
Correct |
152 ms |
65200 KB |
Output is correct |
3 |
Correct |
77 ms |
53476 KB |
Output is correct |
4 |
Correct |
93 ms |
53404 KB |
Output is correct |
5 |
Correct |
263 ms |
88880 KB |
Output is correct |
6 |
Correct |
350 ms |
101576 KB |
Output is correct |
7 |
Correct |
9 ms |
18968 KB |
Output is correct |
8 |
Correct |
201 ms |
69468 KB |
Output is correct |
9 |
Correct |
214 ms |
77224 KB |
Output is correct |
10 |
Correct |
129 ms |
59572 KB |
Output is correct |
11 |
Correct |
143 ms |
65308 KB |
Output is correct |
12 |
Correct |
9 ms |
19028 KB |
Output is correct |
13 |
Correct |
9 ms |
19028 KB |
Output is correct |
14 |
Correct |
8 ms |
19028 KB |
Output is correct |
15 |
Correct |
9 ms |
19028 KB |
Output is correct |
16 |
Correct |
98 ms |
53408 KB |
Output is correct |
17 |
Correct |
78 ms |
53484 KB |
Output is correct |
18 |
Correct |
137 ms |
59612 KB |
Output is correct |
19 |
Correct |
147 ms |
65284 KB |
Output is correct |
20 |
Correct |
152 ms |
59844 KB |
Output is correct |
21 |
Correct |
156 ms |
64392 KB |
Output is correct |
22 |
Correct |
133 ms |
59852 KB |
Output is correct |
23 |
Correct |
149 ms |
64244 KB |
Output is correct |
24 |
Correct |
77 ms |
53516 KB |
Output is correct |
25 |
Correct |
79 ms |
53436 KB |
Output is correct |
26 |
Correct |
111 ms |
52912 KB |
Output is correct |
27 |
Correct |
113 ms |
55592 KB |
Output is correct |
28 |
Correct |
150 ms |
59820 KB |
Output is correct |
29 |
Correct |
133 ms |
59824 KB |
Output is correct |
30 |
Correct |
122 ms |
59804 KB |
Output is correct |
31 |
Correct |
119 ms |
59816 KB |
Output is correct |
32 |
Correct |
9 ms |
19028 KB |
Output is correct |
33 |
Correct |
9 ms |
19016 KB |
Output is correct |
34 |
Correct |
9 ms |
19088 KB |
Output is correct |
35 |
Correct |
9 ms |
19028 KB |
Output is correct |
36 |
Correct |
9 ms |
19068 KB |
Output is correct |
37 |
Correct |
11 ms |
19028 KB |
Output is correct |
38 |
Correct |
8 ms |
19028 KB |
Output is correct |
39 |
Correct |
12 ms |
19028 KB |
Output is correct |
40 |
Correct |
9 ms |
19236 KB |
Output is correct |
41 |
Correct |
13 ms |
19640 KB |
Output is correct |
42 |
Correct |
8 ms |
19184 KB |
Output is correct |
43 |
Correct |
8 ms |
19284 KB |
Output is correct |
44 |
Correct |
8 ms |
19028 KB |
Output is correct |
45 |
Correct |
11 ms |
19272 KB |
Output is correct |
46 |
Correct |
12 ms |
19152 KB |
Output is correct |
47 |
Correct |
10 ms |
19440 KB |
Output is correct |
48 |
Correct |
31 ms |
24764 KB |
Output is correct |
49 |
Correct |
31 ms |
28200 KB |
Output is correct |
50 |
Correct |
31 ms |
27392 KB |
Output is correct |
51 |
Correct |
31 ms |
27444 KB |
Output is correct |
52 |
Correct |
29 ms |
27424 KB |
Output is correct |
53 |
Correct |
52 ms |
35772 KB |
Output is correct |
54 |
Correct |
14 ms |
20604 KB |
Output is correct |
55 |
Correct |
24 ms |
23508 KB |
Output is correct |
56 |
Correct |
10 ms |
19284 KB |
Output is correct |
57 |
Correct |
13 ms |
20436 KB |
Output is correct |
58 |
Correct |
12 ms |
20564 KB |
Output is correct |
59 |
Correct |
123 ms |
56568 KB |
Output is correct |
60 |
Correct |
184 ms |
64716 KB |
Output is correct |
61 |
Correct |
157 ms |
62796 KB |
Output is correct |
62 |
Correct |
153 ms |
62756 KB |
Output is correct |
63 |
Correct |
163 ms |
74200 KB |
Output is correct |
64 |
Correct |
163 ms |
62812 KB |
Output is correct |
65 |
Correct |
152 ms |
62820 KB |
Output is correct |
66 |
Correct |
66 ms |
38892 KB |
Output is correct |
67 |
Correct |
165 ms |
72388 KB |
Output is correct |
68 |
Correct |
134 ms |
69280 KB |
Output is correct |
69 |
Correct |
84 ms |
46592 KB |
Output is correct |
70 |
Correct |
167 ms |
74188 KB |
Output is correct |
71 |
Correct |
9 ms |
19032 KB |
Output is correct |
72 |
Correct |
12 ms |
19028 KB |
Output is correct |
73 |
Correct |
9 ms |
19096 KB |
Output is correct |
74 |
Correct |
8 ms |
19028 KB |
Output is correct |
75 |
Correct |
9 ms |
19028 KB |
Output is correct |
76 |
Correct |
11 ms |
19028 KB |
Output is correct |
77 |
Correct |
75 ms |
53508 KB |
Output is correct |
78 |
Correct |
77 ms |
53508 KB |
Output is correct |
79 |
Correct |
76 ms |
53508 KB |
Output is correct |
80 |
Correct |
78 ms |
53480 KB |
Output is correct |
81 |
Correct |
164 ms |
68260 KB |
Output is correct |
82 |
Correct |
205 ms |
82964 KB |
Output is correct |
83 |
Correct |
187 ms |
83540 KB |
Output is correct |
84 |
Correct |
269 ms |
87604 KB |
Output is correct |
85 |
Correct |
281 ms |
92408 KB |
Output is correct |
86 |
Correct |
309 ms |
96792 KB |
Output is correct |
87 |
Correct |
331 ms |
100820 KB |
Output is correct |
88 |
Correct |
9 ms |
19028 KB |
Output is correct |
89 |
Correct |
320 ms |
100824 KB |
Output is correct |
90 |
Correct |
266 ms |
99000 KB |
Output is correct |
91 |
Correct |
256 ms |
99660 KB |
Output is correct |