#include <bits/stdc++.h>
#include "fish.h"
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define pii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define sz(x) int(x.size())
#define ll long long
using namespace std;
const int N = 2e5 + 5;
#define inf 2e18
ll max_weights(int n,int m,vi X,vi Y,vi W){
vector <vector<pii>> vec(n);
rep(i,0,m)vec[X[i]].pb({Y[i],W[i]});
vector <ll> f,g,lstf,lstg,Mx(n,-inf);
rep(x,0,n){
sort(ALL(vec[x]));
int m = sz(vec[x]);
swap(f,lstf),swap(g,lstg);
f = g = vector <ll> (m,-inf);
int j = sz(lstf) - 1;
ll mxlst = -inf,mxcur = -inf;
if(x){
per(i,m - 1,0){
int y = vec[x][i].fi,w = vec[x][i].se;
f[i] = max(mxcur,0ll) + w;
if(x > 1)f[i] = max(f[i],Mx[x - 2] + w);
while(j >= 0 && vec[x - 1][j].fi > y){
mxlst = max(mxlst,lstf[j]);
j--;
}
f[i] = max(f[i],mxlst + w);
mxcur = max(mxcur,f[i]);
}
}
if(sz(lstf))mxlst = *max_element(ALL(lstf));
ll mxlstg = -inf,mxcurg = -inf;
if(x < n - 1){
j = 0;
rep(i,0,m){
int y = vec[x][i].fi,w = vec[x][i].se;
g[i] = max(mxcurg,0ll) + w;
if(x >= 2)g[i] = max(g[i],Mx[x - 2] + w);
//no pier is on x when considering mxlstf
g[i] = max(g[i],mxlst + w);
while(j < sz(lstg) && vec[x - 1][j].fi < y){
mxlstg = max(mxlstg,lstg[j]);
j++;
}
g[i] = max(g[i],mxlstg + w);
mxcurg = max(mxcurg,g[i]);
}
}
if(x)Mx[x] = Mx[x - 1];
//the maximum answer we can get in the first x columns
Mx[x] = max(Mx[x],max(mxcur,mxcurg));
}
return Mx[n - 1];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
6996 KB |
Output is correct |
2 |
Correct |
39 ms |
8252 KB |
Output is correct |
3 |
Correct |
4 ms |
3412 KB |
Output is correct |
4 |
Correct |
3 ms |
3412 KB |
Output is correct |
5 |
Correct |
113 ms |
14428 KB |
Output is correct |
6 |
Correct |
119 ms |
14820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
63 ms |
10808 KB |
Output is correct |
3 |
Correct |
83 ms |
13004 KB |
Output is correct |
4 |
Correct |
33 ms |
7004 KB |
Output is correct |
5 |
Correct |
39 ms |
8244 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
3412 KB |
Output is correct |
11 |
Correct |
3 ms |
3412 KB |
Output is correct |
12 |
Correct |
31 ms |
7008 KB |
Output is correct |
13 |
Correct |
38 ms |
8256 KB |
Output is correct |
14 |
Correct |
34 ms |
7172 KB |
Output is correct |
15 |
Correct |
43 ms |
7912 KB |
Output is correct |
16 |
Correct |
32 ms |
7132 KB |
Output is correct |
17 |
Correct |
35 ms |
7744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3412 KB |
Output is correct |
2 |
Correct |
3 ms |
3412 KB |
Output is correct |
3 |
Correct |
23 ms |
5972 KB |
Output is correct |
4 |
Correct |
17 ms |
5408 KB |
Output is correct |
5 |
Correct |
40 ms |
8780 KB |
Output is correct |
6 |
Correct |
37 ms |
8852 KB |
Output is correct |
7 |
Correct |
39 ms |
8908 KB |
Output is correct |
8 |
Correct |
48 ms |
8900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
216 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
216 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
216 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
216 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
16 ms |
1876 KB |
Output is correct |
18 |
Correct |
16 ms |
2124 KB |
Output is correct |
19 |
Correct |
14 ms |
2004 KB |
Output is correct |
20 |
Correct |
14 ms |
2004 KB |
Output is correct |
21 |
Correct |
18 ms |
1988 KB |
Output is correct |
22 |
Correct |
32 ms |
3784 KB |
Output is correct |
23 |
Correct |
3 ms |
596 KB |
Output is correct |
24 |
Correct |
10 ms |
1396 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
3 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
216 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
216 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
16 ms |
1876 KB |
Output is correct |
18 |
Correct |
16 ms |
2124 KB |
Output is correct |
19 |
Correct |
14 ms |
2004 KB |
Output is correct |
20 |
Correct |
14 ms |
2004 KB |
Output is correct |
21 |
Correct |
18 ms |
1988 KB |
Output is correct |
22 |
Correct |
32 ms |
3784 KB |
Output is correct |
23 |
Correct |
3 ms |
596 KB |
Output is correct |
24 |
Correct |
10 ms |
1396 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
3 ms |
596 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
69 ms |
8652 KB |
Output is correct |
29 |
Correct |
101 ms |
11340 KB |
Output is correct |
30 |
Correct |
100 ms |
10700 KB |
Output is correct |
31 |
Correct |
104 ms |
10728 KB |
Output is correct |
32 |
Correct |
93 ms |
12256 KB |
Output is correct |
33 |
Correct |
114 ms |
10732 KB |
Output is correct |
34 |
Correct |
127 ms |
10820 KB |
Output is correct |
35 |
Correct |
38 ms |
4692 KB |
Output is correct |
36 |
Correct |
101 ms |
11748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3412 KB |
Output is correct |
2 |
Correct |
3 ms |
3412 KB |
Output is correct |
3 |
Correct |
23 ms |
5972 KB |
Output is correct |
4 |
Correct |
17 ms |
5408 KB |
Output is correct |
5 |
Correct |
40 ms |
8780 KB |
Output is correct |
6 |
Correct |
37 ms |
8852 KB |
Output is correct |
7 |
Correct |
39 ms |
8908 KB |
Output is correct |
8 |
Correct |
48 ms |
8900 KB |
Output is correct |
9 |
Correct |
40 ms |
8916 KB |
Output is correct |
10 |
Correct |
37 ms |
5768 KB |
Output is correct |
11 |
Correct |
87 ms |
11264 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
3 ms |
3412 KB |
Output is correct |
19 |
Correct |
3 ms |
3412 KB |
Output is correct |
20 |
Correct |
3 ms |
3412 KB |
Output is correct |
21 |
Correct |
3 ms |
3412 KB |
Output is correct |
22 |
Correct |
45 ms |
7752 KB |
Output is correct |
23 |
Correct |
81 ms |
11232 KB |
Output is correct |
24 |
Correct |
77 ms |
11216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
6996 KB |
Output is correct |
2 |
Correct |
39 ms |
8252 KB |
Output is correct |
3 |
Correct |
4 ms |
3412 KB |
Output is correct |
4 |
Correct |
3 ms |
3412 KB |
Output is correct |
5 |
Correct |
113 ms |
14428 KB |
Output is correct |
6 |
Correct |
119 ms |
14820 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
63 ms |
10808 KB |
Output is correct |
9 |
Correct |
83 ms |
13004 KB |
Output is correct |
10 |
Correct |
33 ms |
7004 KB |
Output is correct |
11 |
Correct |
39 ms |
8244 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
3412 KB |
Output is correct |
17 |
Correct |
3 ms |
3412 KB |
Output is correct |
18 |
Correct |
31 ms |
7008 KB |
Output is correct |
19 |
Correct |
38 ms |
8256 KB |
Output is correct |
20 |
Correct |
34 ms |
7172 KB |
Output is correct |
21 |
Correct |
43 ms |
7912 KB |
Output is correct |
22 |
Correct |
32 ms |
7132 KB |
Output is correct |
23 |
Correct |
35 ms |
7744 KB |
Output is correct |
24 |
Correct |
3 ms |
3412 KB |
Output is correct |
25 |
Correct |
3 ms |
3412 KB |
Output is correct |
26 |
Correct |
23 ms |
5972 KB |
Output is correct |
27 |
Correct |
17 ms |
5408 KB |
Output is correct |
28 |
Correct |
40 ms |
8780 KB |
Output is correct |
29 |
Correct |
37 ms |
8852 KB |
Output is correct |
30 |
Correct |
39 ms |
8908 KB |
Output is correct |
31 |
Correct |
48 ms |
8900 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
216 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
216 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
2 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
0 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
16 ms |
1876 KB |
Output is correct |
49 |
Correct |
16 ms |
2124 KB |
Output is correct |
50 |
Correct |
14 ms |
2004 KB |
Output is correct |
51 |
Correct |
14 ms |
2004 KB |
Output is correct |
52 |
Correct |
18 ms |
1988 KB |
Output is correct |
53 |
Correct |
32 ms |
3784 KB |
Output is correct |
54 |
Correct |
3 ms |
596 KB |
Output is correct |
55 |
Correct |
10 ms |
1396 KB |
Output is correct |
56 |
Correct |
1 ms |
340 KB |
Output is correct |
57 |
Correct |
3 ms |
596 KB |
Output is correct |
58 |
Correct |
1 ms |
468 KB |
Output is correct |
59 |
Correct |
69 ms |
8652 KB |
Output is correct |
60 |
Correct |
101 ms |
11340 KB |
Output is correct |
61 |
Correct |
100 ms |
10700 KB |
Output is correct |
62 |
Correct |
104 ms |
10728 KB |
Output is correct |
63 |
Correct |
93 ms |
12256 KB |
Output is correct |
64 |
Correct |
114 ms |
10732 KB |
Output is correct |
65 |
Correct |
127 ms |
10820 KB |
Output is correct |
66 |
Correct |
38 ms |
4692 KB |
Output is correct |
67 |
Correct |
101 ms |
11748 KB |
Output is correct |
68 |
Correct |
40 ms |
8916 KB |
Output is correct |
69 |
Correct |
37 ms |
5768 KB |
Output is correct |
70 |
Correct |
87 ms |
11264 KB |
Output is correct |
71 |
Correct |
0 ms |
212 KB |
Output is correct |
72 |
Correct |
1 ms |
212 KB |
Output is correct |
73 |
Correct |
1 ms |
212 KB |
Output is correct |
74 |
Correct |
0 ms |
212 KB |
Output is correct |
75 |
Correct |
1 ms |
212 KB |
Output is correct |
76 |
Correct |
0 ms |
212 KB |
Output is correct |
77 |
Correct |
3 ms |
3412 KB |
Output is correct |
78 |
Correct |
3 ms |
3412 KB |
Output is correct |
79 |
Correct |
3 ms |
3412 KB |
Output is correct |
80 |
Correct |
3 ms |
3412 KB |
Output is correct |
81 |
Correct |
45 ms |
7752 KB |
Output is correct |
82 |
Correct |
81 ms |
11232 KB |
Output is correct |
83 |
Correct |
77 ms |
11216 KB |
Output is correct |
84 |
Correct |
114 ms |
14136 KB |
Output is correct |
85 |
Correct |
109 ms |
14220 KB |
Output is correct |
86 |
Correct |
121 ms |
14928 KB |
Output is correct |
87 |
Correct |
123 ms |
15392 KB |
Output is correct |
88 |
Correct |
0 ms |
212 KB |
Output is correct |
89 |
Correct |
130 ms |
15392 KB |
Output is correct |
90 |
Correct |
112 ms |
14908 KB |
Output is correct |
91 |
Correct |
108 ms |
14540 KB |
Output is correct |