#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rng(i,a,b) for(int i=int(a);i<=int(b);i++)
#define rep(i,b) rng(i,0,b-1)
#define gnr(i,b,a) for(int i=int(b);i>=int(a);i--)
#define per(i,b) gnr(i,b-1,0)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define si(x) int(x.size())
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pii=pair<int,int>;
using vi=vc<int>;
using uint=unsigned;
using ull=unsigned ll;
using pil=pair<int,ll>;
using pli=pair<ll,int>;
using pll=pair<ll,ll>;
using t3=tuple<int,int,int>;
#define N_ 101000
vc<pii>Z[N_];
vc<int>YY[N_], GG[N_];
vc<ll>D1[N_], D2[N_];
int n, m;
map<int,int>MM[N_];
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
n=N,m=M;
rep(i,M){
Y[i]++;
Z[X[i]].pb({Y[i],W[i]});
MM[X[i]][Y[i]] = W[i];
}
rep(i,N){
sort(all(Z[i]));
}
rep(i,N){
rng(j,i-1,i+1){
if(j<0||j>=N)continue;
for(auto [y,w] : Z[j]){
YY[i].pb(y);
}
}
YY[i].pb(0);
sort(all(YY[i]));
YY[i].resize(unique(all(YY[i])) - YY[i].begin());
D1[i].resize(si(YY[i]));
D2[i].resize(si(YY[i]));
rep(j,si(YY[i])){
GG[i].pb(MM[i][YY[i][j]]);
}
}
ll INF = 1e18;
rng(i,1,N-1){
ll s = 0;
int pv = 0;
ll Mx = -INF;
ll pM = 0;
rep(j,si(YY[i-1])){
pM=max(pM, D1[i-1][j]);
pM=max(pM, D2[i-1][j]);
}
rep(j,si(YY[i])){
while(pv < si(YY[i-1]) && YY[i-1][pv] <= YY[i][j]){
int y = YY[i-1][pv];
int g = GG[i-1][pv];
s += g;
Mx=max(Mx, D1[i-1][pv]-s);
pv++;
}
D1[i][j] = max({D1[i][j], Mx + s, pM});
}
Mx = -INF;
pv = si(YY[i-1]) - 1;
per(j,si(YY[i])){
while(pv >= 0 && YY[i-1][pv] > YY[i][j]){
int y = YY[i-1][pv];
int g = MM[i][y];
Mx=max(Mx, max(D1[i-1][pv], D2[i-1][pv])-s);
pv--;
s += g;
}
D2[i][j] = max({D2[i][j], Mx + s, pM});
}
//printf("%d\n",i);
//rep(j,si(YY[i])){
//printf("%lld %lld\n",D1[i][j],D2[i][j]);
//}
}
ll ans=0;
rep(i,si(YY[N-1])){
ans=max({ans, D1[N-1][i], D2[N-1][i]});
}
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:78:13: warning: unused variable 'y' [-Wunused-variable]
78 | int y = YY[i-1][pv];
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
153 ms |
50104 KB |
Output is correct |
2 |
Correct |
193 ms |
55968 KB |
Output is correct |
3 |
Correct |
43 ms |
34004 KB |
Output is correct |
4 |
Correct |
48 ms |
34104 KB |
Output is correct |
5 |
Correct |
657 ms |
121016 KB |
Output is correct |
6 |
Correct |
534 ms |
120748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
16820 KB |
Output is correct |
2 |
Correct |
296 ms |
60476 KB |
Output is correct |
3 |
Correct |
338 ms |
67112 KB |
Output is correct |
4 |
Correct |
156 ms |
50032 KB |
Output is correct |
5 |
Correct |
189 ms |
55952 KB |
Output is correct |
6 |
Correct |
9 ms |
16852 KB |
Output is correct |
7 |
Correct |
9 ms |
16852 KB |
Output is correct |
8 |
Correct |
10 ms |
16852 KB |
Output is correct |
9 |
Correct |
10 ms |
16884 KB |
Output is correct |
10 |
Correct |
42 ms |
34040 KB |
Output is correct |
11 |
Correct |
43 ms |
34012 KB |
Output is correct |
12 |
Correct |
191 ms |
55896 KB |
Output is correct |
13 |
Correct |
214 ms |
63012 KB |
Output is correct |
14 |
Correct |
158 ms |
53028 KB |
Output is correct |
15 |
Correct |
170 ms |
49672 KB |
Output is correct |
16 |
Correct |
184 ms |
53056 KB |
Output is correct |
17 |
Correct |
193 ms |
56964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
33996 KB |
Output is correct |
2 |
Correct |
42 ms |
34108 KB |
Output is correct |
3 |
Correct |
110 ms |
38136 KB |
Output is correct |
4 |
Correct |
87 ms |
38348 KB |
Output is correct |
5 |
Correct |
127 ms |
44332 KB |
Output is correct |
6 |
Correct |
122 ms |
44432 KB |
Output is correct |
7 |
Correct |
134 ms |
44548 KB |
Output is correct |
8 |
Correct |
129 ms |
44528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
16852 KB |
Output is correct |
2 |
Correct |
10 ms |
16852 KB |
Output is correct |
3 |
Correct |
9 ms |
16852 KB |
Output is correct |
4 |
Correct |
9 ms |
16792 KB |
Output is correct |
5 |
Correct |
9 ms |
16852 KB |
Output is correct |
6 |
Correct |
9 ms |
16908 KB |
Output is correct |
7 |
Correct |
12 ms |
16856 KB |
Output is correct |
8 |
Correct |
9 ms |
16852 KB |
Output is correct |
9 |
Correct |
9 ms |
16980 KB |
Output is correct |
10 |
Correct |
10 ms |
17236 KB |
Output is correct |
11 |
Correct |
10 ms |
16980 KB |
Output is correct |
12 |
Correct |
13 ms |
17068 KB |
Output is correct |
13 |
Correct |
9 ms |
16928 KB |
Output is correct |
14 |
Correct |
12 ms |
17044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
16852 KB |
Output is correct |
2 |
Correct |
10 ms |
16852 KB |
Output is correct |
3 |
Correct |
9 ms |
16852 KB |
Output is correct |
4 |
Correct |
9 ms |
16792 KB |
Output is correct |
5 |
Correct |
9 ms |
16852 KB |
Output is correct |
6 |
Correct |
9 ms |
16908 KB |
Output is correct |
7 |
Correct |
12 ms |
16856 KB |
Output is correct |
8 |
Correct |
9 ms |
16852 KB |
Output is correct |
9 |
Correct |
9 ms |
16980 KB |
Output is correct |
10 |
Correct |
10 ms |
17236 KB |
Output is correct |
11 |
Correct |
10 ms |
16980 KB |
Output is correct |
12 |
Correct |
13 ms |
17068 KB |
Output is correct |
13 |
Correct |
9 ms |
16928 KB |
Output is correct |
14 |
Correct |
12 ms |
17044 KB |
Output is correct |
15 |
Correct |
10 ms |
16956 KB |
Output is correct |
16 |
Correct |
10 ms |
17176 KB |
Output is correct |
17 |
Correct |
56 ms |
23708 KB |
Output is correct |
18 |
Correct |
52 ms |
23108 KB |
Output is correct |
19 |
Correct |
57 ms |
23348 KB |
Output is correct |
20 |
Correct |
45 ms |
22636 KB |
Output is correct |
21 |
Correct |
59 ms |
22568 KB |
Output is correct |
22 |
Correct |
94 ms |
27984 KB |
Output is correct |
23 |
Correct |
22 ms |
19460 KB |
Output is correct |
24 |
Correct |
43 ms |
23460 KB |
Output is correct |
25 |
Correct |
10 ms |
17108 KB |
Output is correct |
26 |
Correct |
17 ms |
19000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
16852 KB |
Output is correct |
2 |
Correct |
10 ms |
16852 KB |
Output is correct |
3 |
Correct |
9 ms |
16852 KB |
Output is correct |
4 |
Correct |
9 ms |
16792 KB |
Output is correct |
5 |
Correct |
9 ms |
16852 KB |
Output is correct |
6 |
Correct |
9 ms |
16908 KB |
Output is correct |
7 |
Correct |
12 ms |
16856 KB |
Output is correct |
8 |
Correct |
9 ms |
16852 KB |
Output is correct |
9 |
Correct |
9 ms |
16980 KB |
Output is correct |
10 |
Correct |
10 ms |
17236 KB |
Output is correct |
11 |
Correct |
10 ms |
16980 KB |
Output is correct |
12 |
Correct |
13 ms |
17068 KB |
Output is correct |
13 |
Correct |
9 ms |
16928 KB |
Output is correct |
14 |
Correct |
12 ms |
17044 KB |
Output is correct |
15 |
Correct |
10 ms |
16956 KB |
Output is correct |
16 |
Correct |
10 ms |
17176 KB |
Output is correct |
17 |
Correct |
56 ms |
23708 KB |
Output is correct |
18 |
Correct |
52 ms |
23108 KB |
Output is correct |
19 |
Correct |
57 ms |
23348 KB |
Output is correct |
20 |
Correct |
45 ms |
22636 KB |
Output is correct |
21 |
Correct |
59 ms |
22568 KB |
Output is correct |
22 |
Correct |
94 ms |
27984 KB |
Output is correct |
23 |
Correct |
22 ms |
19460 KB |
Output is correct |
24 |
Correct |
43 ms |
23460 KB |
Output is correct |
25 |
Correct |
10 ms |
17108 KB |
Output is correct |
26 |
Correct |
17 ms |
19000 KB |
Output is correct |
27 |
Correct |
13 ms |
18200 KB |
Output is correct |
28 |
Correct |
274 ms |
46904 KB |
Output is correct |
29 |
Correct |
453 ms |
68888 KB |
Output is correct |
30 |
Correct |
544 ms |
105180 KB |
Output is correct |
31 |
Correct |
526 ms |
103988 KB |
Output is correct |
32 |
Correct |
361 ms |
54220 KB |
Output is correct |
33 |
Correct |
531 ms |
107172 KB |
Output is correct |
34 |
Correct |
542 ms |
107240 KB |
Output is correct |
35 |
Correct |
151 ms |
43264 KB |
Output is correct |
36 |
Correct |
605 ms |
90984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
33996 KB |
Output is correct |
2 |
Correct |
42 ms |
34108 KB |
Output is correct |
3 |
Correct |
110 ms |
38136 KB |
Output is correct |
4 |
Correct |
87 ms |
38348 KB |
Output is correct |
5 |
Correct |
127 ms |
44332 KB |
Output is correct |
6 |
Correct |
122 ms |
44432 KB |
Output is correct |
7 |
Correct |
134 ms |
44548 KB |
Output is correct |
8 |
Correct |
129 ms |
44528 KB |
Output is correct |
9 |
Correct |
200 ms |
61744 KB |
Output is correct |
10 |
Correct |
114 ms |
35132 KB |
Output is correct |
11 |
Correct |
249 ms |
53600 KB |
Output is correct |
12 |
Correct |
9 ms |
16852 KB |
Output is correct |
13 |
Correct |
9 ms |
16852 KB |
Output is correct |
14 |
Correct |
9 ms |
16876 KB |
Output is correct |
15 |
Correct |
10 ms |
16852 KB |
Output is correct |
16 |
Correct |
10 ms |
16852 KB |
Output is correct |
17 |
Correct |
9 ms |
16852 KB |
Output is correct |
18 |
Correct |
49 ms |
34100 KB |
Output is correct |
19 |
Correct |
47 ms |
34116 KB |
Output is correct |
20 |
Correct |
51 ms |
33996 KB |
Output is correct |
21 |
Correct |
54 ms |
34016 KB |
Output is correct |
22 |
Correct |
250 ms |
61036 KB |
Output is correct |
23 |
Correct |
354 ms |
69580 KB |
Output is correct |
24 |
Correct |
335 ms |
72484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
153 ms |
50104 KB |
Output is correct |
2 |
Correct |
193 ms |
55968 KB |
Output is correct |
3 |
Correct |
43 ms |
34004 KB |
Output is correct |
4 |
Correct |
48 ms |
34104 KB |
Output is correct |
5 |
Correct |
657 ms |
121016 KB |
Output is correct |
6 |
Correct |
534 ms |
120748 KB |
Output is correct |
7 |
Correct |
9 ms |
16820 KB |
Output is correct |
8 |
Correct |
296 ms |
60476 KB |
Output is correct |
9 |
Correct |
338 ms |
67112 KB |
Output is correct |
10 |
Correct |
156 ms |
50032 KB |
Output is correct |
11 |
Correct |
189 ms |
55952 KB |
Output is correct |
12 |
Correct |
9 ms |
16852 KB |
Output is correct |
13 |
Correct |
9 ms |
16852 KB |
Output is correct |
14 |
Correct |
10 ms |
16852 KB |
Output is correct |
15 |
Correct |
10 ms |
16884 KB |
Output is correct |
16 |
Correct |
42 ms |
34040 KB |
Output is correct |
17 |
Correct |
43 ms |
34012 KB |
Output is correct |
18 |
Correct |
191 ms |
55896 KB |
Output is correct |
19 |
Correct |
214 ms |
63012 KB |
Output is correct |
20 |
Correct |
158 ms |
53028 KB |
Output is correct |
21 |
Correct |
170 ms |
49672 KB |
Output is correct |
22 |
Correct |
184 ms |
53056 KB |
Output is correct |
23 |
Correct |
193 ms |
56964 KB |
Output is correct |
24 |
Correct |
43 ms |
33996 KB |
Output is correct |
25 |
Correct |
42 ms |
34108 KB |
Output is correct |
26 |
Correct |
110 ms |
38136 KB |
Output is correct |
27 |
Correct |
87 ms |
38348 KB |
Output is correct |
28 |
Correct |
127 ms |
44332 KB |
Output is correct |
29 |
Correct |
122 ms |
44432 KB |
Output is correct |
30 |
Correct |
134 ms |
44548 KB |
Output is correct |
31 |
Correct |
129 ms |
44528 KB |
Output is correct |
32 |
Correct |
9 ms |
16852 KB |
Output is correct |
33 |
Correct |
10 ms |
16852 KB |
Output is correct |
34 |
Correct |
9 ms |
16852 KB |
Output is correct |
35 |
Correct |
9 ms |
16792 KB |
Output is correct |
36 |
Correct |
9 ms |
16852 KB |
Output is correct |
37 |
Correct |
9 ms |
16908 KB |
Output is correct |
38 |
Correct |
12 ms |
16856 KB |
Output is correct |
39 |
Correct |
9 ms |
16852 KB |
Output is correct |
40 |
Correct |
9 ms |
16980 KB |
Output is correct |
41 |
Correct |
10 ms |
17236 KB |
Output is correct |
42 |
Correct |
10 ms |
16980 KB |
Output is correct |
43 |
Correct |
13 ms |
17068 KB |
Output is correct |
44 |
Correct |
9 ms |
16928 KB |
Output is correct |
45 |
Correct |
12 ms |
17044 KB |
Output is correct |
46 |
Correct |
10 ms |
16956 KB |
Output is correct |
47 |
Correct |
10 ms |
17176 KB |
Output is correct |
48 |
Correct |
56 ms |
23708 KB |
Output is correct |
49 |
Correct |
52 ms |
23108 KB |
Output is correct |
50 |
Correct |
57 ms |
23348 KB |
Output is correct |
51 |
Correct |
45 ms |
22636 KB |
Output is correct |
52 |
Correct |
59 ms |
22568 KB |
Output is correct |
53 |
Correct |
94 ms |
27984 KB |
Output is correct |
54 |
Correct |
22 ms |
19460 KB |
Output is correct |
55 |
Correct |
43 ms |
23460 KB |
Output is correct |
56 |
Correct |
10 ms |
17108 KB |
Output is correct |
57 |
Correct |
17 ms |
19000 KB |
Output is correct |
58 |
Correct |
13 ms |
18200 KB |
Output is correct |
59 |
Correct |
274 ms |
46904 KB |
Output is correct |
60 |
Correct |
453 ms |
68888 KB |
Output is correct |
61 |
Correct |
544 ms |
105180 KB |
Output is correct |
62 |
Correct |
526 ms |
103988 KB |
Output is correct |
63 |
Correct |
361 ms |
54220 KB |
Output is correct |
64 |
Correct |
531 ms |
107172 KB |
Output is correct |
65 |
Correct |
542 ms |
107240 KB |
Output is correct |
66 |
Correct |
151 ms |
43264 KB |
Output is correct |
67 |
Correct |
605 ms |
90984 KB |
Output is correct |
68 |
Correct |
200 ms |
61744 KB |
Output is correct |
69 |
Correct |
114 ms |
35132 KB |
Output is correct |
70 |
Correct |
249 ms |
53600 KB |
Output is correct |
71 |
Correct |
9 ms |
16852 KB |
Output is correct |
72 |
Correct |
9 ms |
16852 KB |
Output is correct |
73 |
Correct |
9 ms |
16876 KB |
Output is correct |
74 |
Correct |
10 ms |
16852 KB |
Output is correct |
75 |
Correct |
10 ms |
16852 KB |
Output is correct |
76 |
Correct |
9 ms |
16852 KB |
Output is correct |
77 |
Correct |
49 ms |
34100 KB |
Output is correct |
78 |
Correct |
47 ms |
34116 KB |
Output is correct |
79 |
Correct |
51 ms |
33996 KB |
Output is correct |
80 |
Correct |
54 ms |
34016 KB |
Output is correct |
81 |
Correct |
250 ms |
61036 KB |
Output is correct |
82 |
Correct |
354 ms |
69580 KB |
Output is correct |
83 |
Correct |
335 ms |
72484 KB |
Output is correct |
84 |
Correct |
692 ms |
108432 KB |
Output is correct |
85 |
Correct |
671 ms |
109180 KB |
Output is correct |
86 |
Correct |
580 ms |
120200 KB |
Output is correct |
87 |
Correct |
599 ms |
122456 KB |
Output is correct |
88 |
Correct |
10 ms |
16904 KB |
Output is correct |
89 |
Correct |
562 ms |
122356 KB |
Output is correct |
90 |
Correct |
478 ms |
98664 KB |
Output is correct |
91 |
Correct |
462 ms |
76464 KB |
Output is correct |