#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
#define MP make_pair
typedef long long ll;
const int maxn=(1e5)+10;
int n,m;
vector<pair<int,int> > vec[maxn];
vector<int> pos[maxn];
vector<ll> dp[maxn][2];
vector<ll> sum[maxn];
ll S(int i,int j) {
j=lower_bound(vec[i].begin(),vec[i].end(),MP(j+1,0))-vec[i].begin()-1;
if (j<0) return 0;
return sum[i][j];
}
const ll INF=1e18;
void chkmax(ll &x,ll y) { if (x<y) x=y; }
ll max_weights(int _n,int _m,vector<int> X,vector<int> Y,vector<int> W) {
n=_n,m=_m;
for (int i=0;i<m;i++) Y[i]++,vec[X[i]].push_back(MP(Y[i],W[i]));
for (int i=0;i<n;i++) {
sort(vec[i].begin(),vec[i].end());
ll pre=0; pos[i].push_back(0);
for (int j=0;j<vec[i].size();j++) {
pre+=vec[i][j].second;
sum[i].push_back(pre);
int p=vec[i][j].first;
if (i>0) pos[i-1].push_back(p);
pos[i].push_back(p-1);
if (i<n-1) pos[i+1].push_back(p);
}
}
for (int i=0;i<n;i++) {
sort(pos[i].begin(),pos[i].end());
pos[i].resize(unique(pos[i].begin(),pos[i].end())-pos[i].begin());
//for (int &x : pos[i]) printf("%d %d\n",i,x);
dp[i][0].resize(pos[i].size());
dp[i][1].resize(pos[i].size());
if (i==0) continue;
ll m0=-INF,m1=-INF,m3=-INF,m4=-INF;
for (int j=0;j<pos[i-1].size();j++) {
chkmax(dp[i-1][1][j],dp[i-1][0][j]);
chkmax(m0,dp[i-1][0][j]-S(i-1,pos[i-1][j]));
// if (i==1) printf("%d %lld\n",pos[i-1][j],S(i-1,pos[i-1][j]));
chkmax(m1,dp[i-1][1][j]);
ll tmp=S(i,pos[i-1][j]);
chkmax(m3,dp[i-1][1][j]+tmp);
chkmax(m4,dp[i-1][0][j]-S(i-1,pos[i-1][j])+tmp);
}
for (int j=0;j<pos[i].size();j++) {
chkmax(dp[i][0][j],max(m0+S(i-1,pos[i][j]),m1));
chkmax(dp[i][1][j],max(m3,m4+S(i-1,pos[i][j]))-S(i,pos[i][j]));
// printf("i=%d,pos=%d,dp=%lld %lld\n",i,pos[i][j],dp[i][0][j],dp[i][1][j]);
}
}
ll ans=0;
for (ll &j : dp[n-1][0]) chkmax(ans,j);
for (ll &j : dp[n-1][1]) chkmax(ans,j);
return ans;
}
Compilation message
fish.cpp: In function 'll max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:25:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for (int j=0;j<vec[i].size();j++) {
| ~^~~~~~~~~~~~~~
fish.cpp:42:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int j=0;j<pos[i-1].size();j++) {
| ~^~~~~~~~~~~~~~~~
fish.cpp:52:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for (int j=0;j<pos[i].size();j++) {
| ~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
26896 KB |
Output is correct |
2 |
Correct |
110 ms |
29380 KB |
Output is correct |
3 |
Correct |
25 ms |
21356 KB |
Output is correct |
4 |
Correct |
24 ms |
21360 KB |
Output is correct |
5 |
Correct |
248 ms |
51308 KB |
Output is correct |
6 |
Correct |
267 ms |
51780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
11988 KB |
Output is correct |
2 |
Correct |
160 ms |
32912 KB |
Output is correct |
3 |
Correct |
181 ms |
36000 KB |
Output is correct |
4 |
Correct |
78 ms |
26936 KB |
Output is correct |
5 |
Correct |
108 ms |
29324 KB |
Output is correct |
6 |
Correct |
6 ms |
12040 KB |
Output is correct |
7 |
Correct |
7 ms |
11988 KB |
Output is correct |
8 |
Correct |
6 ms |
11988 KB |
Output is correct |
9 |
Correct |
6 ms |
11988 KB |
Output is correct |
10 |
Correct |
23 ms |
21356 KB |
Output is correct |
11 |
Correct |
24 ms |
21332 KB |
Output is correct |
12 |
Correct |
86 ms |
28596 KB |
Output is correct |
13 |
Correct |
107 ms |
31372 KB |
Output is correct |
14 |
Correct |
99 ms |
27780 KB |
Output is correct |
15 |
Correct |
121 ms |
28272 KB |
Output is correct |
16 |
Correct |
82 ms |
27876 KB |
Output is correct |
17 |
Correct |
92 ms |
29464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
21432 KB |
Output is correct |
2 |
Correct |
23 ms |
21360 KB |
Output is correct |
3 |
Correct |
67 ms |
25072 KB |
Output is correct |
4 |
Correct |
51 ms |
24432 KB |
Output is correct |
5 |
Correct |
83 ms |
29992 KB |
Output is correct |
6 |
Correct |
82 ms |
30028 KB |
Output is correct |
7 |
Correct |
87 ms |
29976 KB |
Output is correct |
8 |
Correct |
109 ms |
29988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
11988 KB |
Output is correct |
2 |
Correct |
7 ms |
11988 KB |
Output is correct |
3 |
Correct |
6 ms |
11988 KB |
Output is correct |
4 |
Correct |
7 ms |
11988 KB |
Output is correct |
5 |
Correct |
6 ms |
11988 KB |
Output is correct |
6 |
Correct |
6 ms |
11988 KB |
Output is correct |
7 |
Correct |
6 ms |
11988 KB |
Output is correct |
8 |
Correct |
6 ms |
11988 KB |
Output is correct |
9 |
Correct |
7 ms |
12048 KB |
Output is correct |
10 |
Correct |
7 ms |
12204 KB |
Output is correct |
11 |
Correct |
7 ms |
12116 KB |
Output is correct |
12 |
Correct |
6 ms |
12060 KB |
Output is correct |
13 |
Correct |
6 ms |
12044 KB |
Output is correct |
14 |
Correct |
7 ms |
12116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
11988 KB |
Output is correct |
2 |
Correct |
7 ms |
11988 KB |
Output is correct |
3 |
Correct |
6 ms |
11988 KB |
Output is correct |
4 |
Correct |
7 ms |
11988 KB |
Output is correct |
5 |
Correct |
6 ms |
11988 KB |
Output is correct |
6 |
Correct |
6 ms |
11988 KB |
Output is correct |
7 |
Correct |
6 ms |
11988 KB |
Output is correct |
8 |
Correct |
6 ms |
11988 KB |
Output is correct |
9 |
Correct |
7 ms |
12048 KB |
Output is correct |
10 |
Correct |
7 ms |
12204 KB |
Output is correct |
11 |
Correct |
7 ms |
12116 KB |
Output is correct |
12 |
Correct |
6 ms |
12060 KB |
Output is correct |
13 |
Correct |
6 ms |
12044 KB |
Output is correct |
14 |
Correct |
7 ms |
12116 KB |
Output is correct |
15 |
Correct |
7 ms |
11988 KB |
Output is correct |
16 |
Correct |
8 ms |
12116 KB |
Output is correct |
17 |
Correct |
43 ms |
15592 KB |
Output is correct |
18 |
Correct |
36 ms |
15956 KB |
Output is correct |
19 |
Correct |
31 ms |
15776 KB |
Output is correct |
20 |
Correct |
29 ms |
15640 KB |
Output is correct |
21 |
Correct |
31 ms |
15696 KB |
Output is correct |
22 |
Correct |
57 ms |
19252 KB |
Output is correct |
23 |
Correct |
13 ms |
13012 KB |
Output is correct |
24 |
Correct |
33 ms |
14892 KB |
Output is correct |
25 |
Correct |
8 ms |
12116 KB |
Output is correct |
26 |
Correct |
16 ms |
12920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
11988 KB |
Output is correct |
2 |
Correct |
7 ms |
11988 KB |
Output is correct |
3 |
Correct |
6 ms |
11988 KB |
Output is correct |
4 |
Correct |
7 ms |
11988 KB |
Output is correct |
5 |
Correct |
6 ms |
11988 KB |
Output is correct |
6 |
Correct |
6 ms |
11988 KB |
Output is correct |
7 |
Correct |
6 ms |
11988 KB |
Output is correct |
8 |
Correct |
6 ms |
11988 KB |
Output is correct |
9 |
Correct |
7 ms |
12048 KB |
Output is correct |
10 |
Correct |
7 ms |
12204 KB |
Output is correct |
11 |
Correct |
7 ms |
12116 KB |
Output is correct |
12 |
Correct |
6 ms |
12060 KB |
Output is correct |
13 |
Correct |
6 ms |
12044 KB |
Output is correct |
14 |
Correct |
7 ms |
12116 KB |
Output is correct |
15 |
Correct |
7 ms |
11988 KB |
Output is correct |
16 |
Correct |
8 ms |
12116 KB |
Output is correct |
17 |
Correct |
43 ms |
15592 KB |
Output is correct |
18 |
Correct |
36 ms |
15956 KB |
Output is correct |
19 |
Correct |
31 ms |
15776 KB |
Output is correct |
20 |
Correct |
29 ms |
15640 KB |
Output is correct |
21 |
Correct |
31 ms |
15696 KB |
Output is correct |
22 |
Correct |
57 ms |
19252 KB |
Output is correct |
23 |
Correct |
13 ms |
13012 KB |
Output is correct |
24 |
Correct |
33 ms |
14892 KB |
Output is correct |
25 |
Correct |
8 ms |
12116 KB |
Output is correct |
26 |
Correct |
16 ms |
12920 KB |
Output is correct |
27 |
Correct |
8 ms |
12500 KB |
Output is correct |
28 |
Correct |
162 ms |
30312 KB |
Output is correct |
29 |
Correct |
257 ms |
37636 KB |
Output is correct |
30 |
Correct |
263 ms |
44880 KB |
Output is correct |
31 |
Correct |
268 ms |
44808 KB |
Output is correct |
32 |
Correct |
189 ms |
37312 KB |
Output is correct |
33 |
Correct |
259 ms |
45264 KB |
Output is correct |
34 |
Correct |
265 ms |
45388 KB |
Output is correct |
35 |
Correct |
100 ms |
23656 KB |
Output is correct |
36 |
Correct |
265 ms |
42836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
21432 KB |
Output is correct |
2 |
Correct |
23 ms |
21360 KB |
Output is correct |
3 |
Correct |
67 ms |
25072 KB |
Output is correct |
4 |
Correct |
51 ms |
24432 KB |
Output is correct |
5 |
Correct |
83 ms |
29992 KB |
Output is correct |
6 |
Correct |
82 ms |
30028 KB |
Output is correct |
7 |
Correct |
87 ms |
29976 KB |
Output is correct |
8 |
Correct |
109 ms |
29988 KB |
Output is correct |
9 |
Correct |
85 ms |
29988 KB |
Output is correct |
10 |
Correct |
75 ms |
22884 KB |
Output is correct |
11 |
Correct |
162 ms |
33840 KB |
Output is correct |
12 |
Correct |
7 ms |
11988 KB |
Output is correct |
13 |
Correct |
6 ms |
11988 KB |
Output is correct |
14 |
Correct |
8 ms |
11988 KB |
Output is correct |
15 |
Correct |
6 ms |
11988 KB |
Output is correct |
16 |
Correct |
7 ms |
12044 KB |
Output is correct |
17 |
Correct |
6 ms |
11988 KB |
Output is correct |
18 |
Correct |
23 ms |
21428 KB |
Output is correct |
19 |
Correct |
23 ms |
21388 KB |
Output is correct |
20 |
Correct |
23 ms |
21352 KB |
Output is correct |
21 |
Correct |
30 ms |
21332 KB |
Output is correct |
22 |
Correct |
114 ms |
30892 KB |
Output is correct |
23 |
Correct |
164 ms |
37548 KB |
Output is correct |
24 |
Correct |
149 ms |
37852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
26896 KB |
Output is correct |
2 |
Correct |
110 ms |
29380 KB |
Output is correct |
3 |
Correct |
25 ms |
21356 KB |
Output is correct |
4 |
Correct |
24 ms |
21360 KB |
Output is correct |
5 |
Correct |
248 ms |
51308 KB |
Output is correct |
6 |
Correct |
267 ms |
51780 KB |
Output is correct |
7 |
Correct |
7 ms |
11988 KB |
Output is correct |
8 |
Correct |
160 ms |
32912 KB |
Output is correct |
9 |
Correct |
181 ms |
36000 KB |
Output is correct |
10 |
Correct |
78 ms |
26936 KB |
Output is correct |
11 |
Correct |
108 ms |
29324 KB |
Output is correct |
12 |
Correct |
6 ms |
12040 KB |
Output is correct |
13 |
Correct |
7 ms |
11988 KB |
Output is correct |
14 |
Correct |
6 ms |
11988 KB |
Output is correct |
15 |
Correct |
6 ms |
11988 KB |
Output is correct |
16 |
Correct |
23 ms |
21356 KB |
Output is correct |
17 |
Correct |
24 ms |
21332 KB |
Output is correct |
18 |
Correct |
86 ms |
28596 KB |
Output is correct |
19 |
Correct |
107 ms |
31372 KB |
Output is correct |
20 |
Correct |
99 ms |
27780 KB |
Output is correct |
21 |
Correct |
121 ms |
28272 KB |
Output is correct |
22 |
Correct |
82 ms |
27876 KB |
Output is correct |
23 |
Correct |
92 ms |
29464 KB |
Output is correct |
24 |
Correct |
26 ms |
21432 KB |
Output is correct |
25 |
Correct |
23 ms |
21360 KB |
Output is correct |
26 |
Correct |
67 ms |
25072 KB |
Output is correct |
27 |
Correct |
51 ms |
24432 KB |
Output is correct |
28 |
Correct |
83 ms |
29992 KB |
Output is correct |
29 |
Correct |
82 ms |
30028 KB |
Output is correct |
30 |
Correct |
87 ms |
29976 KB |
Output is correct |
31 |
Correct |
109 ms |
29988 KB |
Output is correct |
32 |
Correct |
7 ms |
11988 KB |
Output is correct |
33 |
Correct |
7 ms |
11988 KB |
Output is correct |
34 |
Correct |
6 ms |
11988 KB |
Output is correct |
35 |
Correct |
7 ms |
11988 KB |
Output is correct |
36 |
Correct |
6 ms |
11988 KB |
Output is correct |
37 |
Correct |
6 ms |
11988 KB |
Output is correct |
38 |
Correct |
6 ms |
11988 KB |
Output is correct |
39 |
Correct |
6 ms |
11988 KB |
Output is correct |
40 |
Correct |
7 ms |
12048 KB |
Output is correct |
41 |
Correct |
7 ms |
12204 KB |
Output is correct |
42 |
Correct |
7 ms |
12116 KB |
Output is correct |
43 |
Correct |
6 ms |
12060 KB |
Output is correct |
44 |
Correct |
6 ms |
12044 KB |
Output is correct |
45 |
Correct |
7 ms |
12116 KB |
Output is correct |
46 |
Correct |
7 ms |
11988 KB |
Output is correct |
47 |
Correct |
8 ms |
12116 KB |
Output is correct |
48 |
Correct |
43 ms |
15592 KB |
Output is correct |
49 |
Correct |
36 ms |
15956 KB |
Output is correct |
50 |
Correct |
31 ms |
15776 KB |
Output is correct |
51 |
Correct |
29 ms |
15640 KB |
Output is correct |
52 |
Correct |
31 ms |
15696 KB |
Output is correct |
53 |
Correct |
57 ms |
19252 KB |
Output is correct |
54 |
Correct |
13 ms |
13012 KB |
Output is correct |
55 |
Correct |
33 ms |
14892 KB |
Output is correct |
56 |
Correct |
8 ms |
12116 KB |
Output is correct |
57 |
Correct |
16 ms |
12920 KB |
Output is correct |
58 |
Correct |
8 ms |
12500 KB |
Output is correct |
59 |
Correct |
162 ms |
30312 KB |
Output is correct |
60 |
Correct |
257 ms |
37636 KB |
Output is correct |
61 |
Correct |
263 ms |
44880 KB |
Output is correct |
62 |
Correct |
268 ms |
44808 KB |
Output is correct |
63 |
Correct |
189 ms |
37312 KB |
Output is correct |
64 |
Correct |
259 ms |
45264 KB |
Output is correct |
65 |
Correct |
265 ms |
45388 KB |
Output is correct |
66 |
Correct |
100 ms |
23656 KB |
Output is correct |
67 |
Correct |
265 ms |
42836 KB |
Output is correct |
68 |
Correct |
85 ms |
29988 KB |
Output is correct |
69 |
Correct |
75 ms |
22884 KB |
Output is correct |
70 |
Correct |
162 ms |
33840 KB |
Output is correct |
71 |
Correct |
7 ms |
11988 KB |
Output is correct |
72 |
Correct |
6 ms |
11988 KB |
Output is correct |
73 |
Correct |
8 ms |
11988 KB |
Output is correct |
74 |
Correct |
6 ms |
11988 KB |
Output is correct |
75 |
Correct |
7 ms |
12044 KB |
Output is correct |
76 |
Correct |
6 ms |
11988 KB |
Output is correct |
77 |
Correct |
23 ms |
21428 KB |
Output is correct |
78 |
Correct |
23 ms |
21388 KB |
Output is correct |
79 |
Correct |
23 ms |
21352 KB |
Output is correct |
80 |
Correct |
30 ms |
21332 KB |
Output is correct |
81 |
Correct |
114 ms |
30892 KB |
Output is correct |
82 |
Correct |
164 ms |
37548 KB |
Output is correct |
83 |
Correct |
149 ms |
37852 KB |
Output is correct |
84 |
Correct |
323 ms |
48992 KB |
Output is correct |
85 |
Correct |
317 ms |
49468 KB |
Output is correct |
86 |
Correct |
247 ms |
51896 KB |
Output is correct |
87 |
Correct |
271 ms |
52928 KB |
Output is correct |
88 |
Correct |
6 ms |
11988 KB |
Output is correct |
89 |
Correct |
254 ms |
52964 KB |
Output is correct |
90 |
Correct |
286 ms |
49968 KB |
Output is correct |
91 |
Correct |
219 ms |
45892 KB |
Output is correct |