#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 |
96 ms |
50116 KB |
Output is correct |
2 |
Correct |
128 ms |
56004 KB |
Output is correct |
3 |
Correct |
21 ms |
34140 KB |
Output is correct |
4 |
Correct |
21 ms |
34140 KB |
Output is correct |
5 |
Correct |
437 ms |
121256 KB |
Output is correct |
6 |
Correct |
294 ms |
120916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
16984 KB |
Output is correct |
2 |
Correct |
182 ms |
60584 KB |
Output is correct |
3 |
Correct |
213 ms |
67048 KB |
Output is correct |
4 |
Correct |
97 ms |
50024 KB |
Output is correct |
5 |
Correct |
122 ms |
55984 KB |
Output is correct |
6 |
Correct |
2 ms |
16988 KB |
Output is correct |
7 |
Correct |
2 ms |
16988 KB |
Output is correct |
8 |
Correct |
3 ms |
16988 KB |
Output is correct |
9 |
Correct |
2 ms |
16988 KB |
Output is correct |
10 |
Correct |
28 ms |
34132 KB |
Output is correct |
11 |
Correct |
21 ms |
34140 KB |
Output is correct |
12 |
Correct |
131 ms |
56012 KB |
Output is correct |
13 |
Correct |
161 ms |
63172 KB |
Output is correct |
14 |
Correct |
97 ms |
53184 KB |
Output is correct |
15 |
Correct |
120 ms |
49764 KB |
Output is correct |
16 |
Correct |
105 ms |
53316 KB |
Output is correct |
17 |
Correct |
118 ms |
57156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
34136 KB |
Output is correct |
2 |
Correct |
21 ms |
34136 KB |
Output is correct |
3 |
Correct |
49 ms |
38224 KB |
Output is correct |
4 |
Correct |
35 ms |
38488 KB |
Output is correct |
5 |
Correct |
77 ms |
44436 KB |
Output is correct |
6 |
Correct |
62 ms |
44372 KB |
Output is correct |
7 |
Correct |
65 ms |
44368 KB |
Output is correct |
8 |
Correct |
64 ms |
44432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
16984 KB |
Output is correct |
2 |
Correct |
2 ms |
16984 KB |
Output is correct |
3 |
Correct |
2 ms |
16988 KB |
Output is correct |
4 |
Correct |
2 ms |
16988 KB |
Output is correct |
5 |
Correct |
2 ms |
16988 KB |
Output is correct |
6 |
Correct |
2 ms |
16988 KB |
Output is correct |
7 |
Correct |
2 ms |
16988 KB |
Output is correct |
8 |
Correct |
2 ms |
16988 KB |
Output is correct |
9 |
Correct |
2 ms |
16988 KB |
Output is correct |
10 |
Correct |
3 ms |
17244 KB |
Output is correct |
11 |
Correct |
2 ms |
16988 KB |
Output is correct |
12 |
Correct |
3 ms |
17244 KB |
Output is correct |
13 |
Correct |
2 ms |
16988 KB |
Output is correct |
14 |
Correct |
3 ms |
16988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
16984 KB |
Output is correct |
2 |
Correct |
2 ms |
16984 KB |
Output is correct |
3 |
Correct |
2 ms |
16988 KB |
Output is correct |
4 |
Correct |
2 ms |
16988 KB |
Output is correct |
5 |
Correct |
2 ms |
16988 KB |
Output is correct |
6 |
Correct |
2 ms |
16988 KB |
Output is correct |
7 |
Correct |
2 ms |
16988 KB |
Output is correct |
8 |
Correct |
2 ms |
16988 KB |
Output is correct |
9 |
Correct |
2 ms |
16988 KB |
Output is correct |
10 |
Correct |
3 ms |
17244 KB |
Output is correct |
11 |
Correct |
2 ms |
16988 KB |
Output is correct |
12 |
Correct |
3 ms |
17244 KB |
Output is correct |
13 |
Correct |
2 ms |
16988 KB |
Output is correct |
14 |
Correct |
3 ms |
16988 KB |
Output is correct |
15 |
Correct |
2 ms |
16988 KB |
Output is correct |
16 |
Correct |
3 ms |
17244 KB |
Output is correct |
17 |
Correct |
29 ms |
23544 KB |
Output is correct |
18 |
Correct |
30 ms |
22952 KB |
Output is correct |
19 |
Correct |
24 ms |
23128 KB |
Output is correct |
20 |
Correct |
24 ms |
22616 KB |
Output is correct |
21 |
Correct |
22 ms |
22444 KB |
Output is correct |
22 |
Correct |
49 ms |
27716 KB |
Output is correct |
23 |
Correct |
9 ms |
19548 KB |
Output is correct |
24 |
Correct |
21 ms |
23284 KB |
Output is correct |
25 |
Correct |
3 ms |
17244 KB |
Output is correct |
26 |
Correct |
7 ms |
19036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
16984 KB |
Output is correct |
2 |
Correct |
2 ms |
16984 KB |
Output is correct |
3 |
Correct |
2 ms |
16988 KB |
Output is correct |
4 |
Correct |
2 ms |
16988 KB |
Output is correct |
5 |
Correct |
2 ms |
16988 KB |
Output is correct |
6 |
Correct |
2 ms |
16988 KB |
Output is correct |
7 |
Correct |
2 ms |
16988 KB |
Output is correct |
8 |
Correct |
2 ms |
16988 KB |
Output is correct |
9 |
Correct |
2 ms |
16988 KB |
Output is correct |
10 |
Correct |
3 ms |
17244 KB |
Output is correct |
11 |
Correct |
2 ms |
16988 KB |
Output is correct |
12 |
Correct |
3 ms |
17244 KB |
Output is correct |
13 |
Correct |
2 ms |
16988 KB |
Output is correct |
14 |
Correct |
3 ms |
16988 KB |
Output is correct |
15 |
Correct |
2 ms |
16988 KB |
Output is correct |
16 |
Correct |
3 ms |
17244 KB |
Output is correct |
17 |
Correct |
29 ms |
23544 KB |
Output is correct |
18 |
Correct |
30 ms |
22952 KB |
Output is correct |
19 |
Correct |
24 ms |
23128 KB |
Output is correct |
20 |
Correct |
24 ms |
22616 KB |
Output is correct |
21 |
Correct |
22 ms |
22444 KB |
Output is correct |
22 |
Correct |
49 ms |
27716 KB |
Output is correct |
23 |
Correct |
9 ms |
19548 KB |
Output is correct |
24 |
Correct |
21 ms |
23284 KB |
Output is correct |
25 |
Correct |
3 ms |
17244 KB |
Output is correct |
26 |
Correct |
7 ms |
19036 KB |
Output is correct |
27 |
Correct |
4 ms |
18268 KB |
Output is correct |
28 |
Correct |
150 ms |
46588 KB |
Output is correct |
29 |
Correct |
258 ms |
68436 KB |
Output is correct |
30 |
Correct |
316 ms |
104656 KB |
Output is correct |
31 |
Correct |
289 ms |
106532 KB |
Output is correct |
32 |
Correct |
183 ms |
56660 KB |
Output is correct |
33 |
Correct |
308 ms |
109908 KB |
Output is correct |
34 |
Correct |
293 ms |
109900 KB |
Output is correct |
35 |
Correct |
81 ms |
44112 KB |
Output is correct |
36 |
Correct |
330 ms |
93460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
34136 KB |
Output is correct |
2 |
Correct |
21 ms |
34136 KB |
Output is correct |
3 |
Correct |
49 ms |
38224 KB |
Output is correct |
4 |
Correct |
35 ms |
38488 KB |
Output is correct |
5 |
Correct |
77 ms |
44436 KB |
Output is correct |
6 |
Correct |
62 ms |
44372 KB |
Output is correct |
7 |
Correct |
65 ms |
44368 KB |
Output is correct |
8 |
Correct |
64 ms |
44432 KB |
Output is correct |
9 |
Correct |
87 ms |
61488 KB |
Output is correct |
10 |
Correct |
50 ms |
35028 KB |
Output is correct |
11 |
Correct |
132 ms |
52984 KB |
Output is correct |
12 |
Correct |
2 ms |
16988 KB |
Output is correct |
13 |
Correct |
4 ms |
16984 KB |
Output is correct |
14 |
Correct |
2 ms |
16988 KB |
Output is correct |
15 |
Correct |
3 ms |
16988 KB |
Output is correct |
16 |
Correct |
2 ms |
16988 KB |
Output is correct |
17 |
Correct |
2 ms |
16988 KB |
Output is correct |
18 |
Correct |
20 ms |
34136 KB |
Output is correct |
19 |
Correct |
21 ms |
34140 KB |
Output is correct |
20 |
Correct |
22 ms |
34140 KB |
Output is correct |
21 |
Correct |
26 ms |
34140 KB |
Output is correct |
22 |
Correct |
120 ms |
60764 KB |
Output is correct |
23 |
Correct |
151 ms |
69320 KB |
Output is correct |
24 |
Correct |
184 ms |
72020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
96 ms |
50116 KB |
Output is correct |
2 |
Correct |
128 ms |
56004 KB |
Output is correct |
3 |
Correct |
21 ms |
34140 KB |
Output is correct |
4 |
Correct |
21 ms |
34140 KB |
Output is correct |
5 |
Correct |
437 ms |
121256 KB |
Output is correct |
6 |
Correct |
294 ms |
120916 KB |
Output is correct |
7 |
Correct |
2 ms |
16984 KB |
Output is correct |
8 |
Correct |
182 ms |
60584 KB |
Output is correct |
9 |
Correct |
213 ms |
67048 KB |
Output is correct |
10 |
Correct |
97 ms |
50024 KB |
Output is correct |
11 |
Correct |
122 ms |
55984 KB |
Output is correct |
12 |
Correct |
2 ms |
16988 KB |
Output is correct |
13 |
Correct |
2 ms |
16988 KB |
Output is correct |
14 |
Correct |
3 ms |
16988 KB |
Output is correct |
15 |
Correct |
2 ms |
16988 KB |
Output is correct |
16 |
Correct |
28 ms |
34132 KB |
Output is correct |
17 |
Correct |
21 ms |
34140 KB |
Output is correct |
18 |
Correct |
131 ms |
56012 KB |
Output is correct |
19 |
Correct |
161 ms |
63172 KB |
Output is correct |
20 |
Correct |
97 ms |
53184 KB |
Output is correct |
21 |
Correct |
120 ms |
49764 KB |
Output is correct |
22 |
Correct |
105 ms |
53316 KB |
Output is correct |
23 |
Correct |
118 ms |
57156 KB |
Output is correct |
24 |
Correct |
21 ms |
34136 KB |
Output is correct |
25 |
Correct |
21 ms |
34136 KB |
Output is correct |
26 |
Correct |
49 ms |
38224 KB |
Output is correct |
27 |
Correct |
35 ms |
38488 KB |
Output is correct |
28 |
Correct |
77 ms |
44436 KB |
Output is correct |
29 |
Correct |
62 ms |
44372 KB |
Output is correct |
30 |
Correct |
65 ms |
44368 KB |
Output is correct |
31 |
Correct |
64 ms |
44432 KB |
Output is correct |
32 |
Correct |
2 ms |
16984 KB |
Output is correct |
33 |
Correct |
2 ms |
16984 KB |
Output is correct |
34 |
Correct |
2 ms |
16988 KB |
Output is correct |
35 |
Correct |
2 ms |
16988 KB |
Output is correct |
36 |
Correct |
2 ms |
16988 KB |
Output is correct |
37 |
Correct |
2 ms |
16988 KB |
Output is correct |
38 |
Correct |
2 ms |
16988 KB |
Output is correct |
39 |
Correct |
2 ms |
16988 KB |
Output is correct |
40 |
Correct |
2 ms |
16988 KB |
Output is correct |
41 |
Correct |
3 ms |
17244 KB |
Output is correct |
42 |
Correct |
2 ms |
16988 KB |
Output is correct |
43 |
Correct |
3 ms |
17244 KB |
Output is correct |
44 |
Correct |
2 ms |
16988 KB |
Output is correct |
45 |
Correct |
3 ms |
16988 KB |
Output is correct |
46 |
Correct |
2 ms |
16988 KB |
Output is correct |
47 |
Correct |
3 ms |
17244 KB |
Output is correct |
48 |
Correct |
29 ms |
23544 KB |
Output is correct |
49 |
Correct |
30 ms |
22952 KB |
Output is correct |
50 |
Correct |
24 ms |
23128 KB |
Output is correct |
51 |
Correct |
24 ms |
22616 KB |
Output is correct |
52 |
Correct |
22 ms |
22444 KB |
Output is correct |
53 |
Correct |
49 ms |
27716 KB |
Output is correct |
54 |
Correct |
9 ms |
19548 KB |
Output is correct |
55 |
Correct |
21 ms |
23284 KB |
Output is correct |
56 |
Correct |
3 ms |
17244 KB |
Output is correct |
57 |
Correct |
7 ms |
19036 KB |
Output is correct |
58 |
Correct |
4 ms |
18268 KB |
Output is correct |
59 |
Correct |
150 ms |
46588 KB |
Output is correct |
60 |
Correct |
258 ms |
68436 KB |
Output is correct |
61 |
Correct |
316 ms |
104656 KB |
Output is correct |
62 |
Correct |
289 ms |
106532 KB |
Output is correct |
63 |
Correct |
183 ms |
56660 KB |
Output is correct |
64 |
Correct |
308 ms |
109908 KB |
Output is correct |
65 |
Correct |
293 ms |
109900 KB |
Output is correct |
66 |
Correct |
81 ms |
44112 KB |
Output is correct |
67 |
Correct |
330 ms |
93460 KB |
Output is correct |
68 |
Correct |
87 ms |
61488 KB |
Output is correct |
69 |
Correct |
50 ms |
35028 KB |
Output is correct |
70 |
Correct |
132 ms |
52984 KB |
Output is correct |
71 |
Correct |
2 ms |
16988 KB |
Output is correct |
72 |
Correct |
4 ms |
16984 KB |
Output is correct |
73 |
Correct |
2 ms |
16988 KB |
Output is correct |
74 |
Correct |
3 ms |
16988 KB |
Output is correct |
75 |
Correct |
2 ms |
16988 KB |
Output is correct |
76 |
Correct |
2 ms |
16988 KB |
Output is correct |
77 |
Correct |
20 ms |
34136 KB |
Output is correct |
78 |
Correct |
21 ms |
34140 KB |
Output is correct |
79 |
Correct |
22 ms |
34140 KB |
Output is correct |
80 |
Correct |
26 ms |
34140 KB |
Output is correct |
81 |
Correct |
120 ms |
60764 KB |
Output is correct |
82 |
Correct |
151 ms |
69320 KB |
Output is correct |
83 |
Correct |
184 ms |
72020 KB |
Output is correct |
84 |
Correct |
447 ms |
110852 KB |
Output is correct |
85 |
Correct |
447 ms |
111904 KB |
Output is correct |
86 |
Correct |
342 ms |
123180 KB |
Output is correct |
87 |
Correct |
385 ms |
125264 KB |
Output is correct |
88 |
Correct |
2 ms |
16988 KB |
Output is correct |
89 |
Correct |
372 ms |
125256 KB |
Output is correct |
90 |
Correct |
347 ms |
101064 KB |
Output is correct |
91 |
Correct |
228 ms |
78932 KB |
Output is correct |