#include "fish.h"
#include <bits/stdc++.h>
using namespace std;typedef long long y6;const int maxn = 2e5 + 2;map <y6, y6> dp [maxn][2];y6 mx [maxn];vector <pair <y6, y6> > p[maxn];vector <pair <y6, y6> > pref [maxn], suff[maxn];vector <y6> pos [maxn];y6 psum (y6 i, y6 j) {auto it = lower_bound(p[i].begin(), p[i].end(), make_pair(j, (y6) 1e18));if (it == p[i].begin()) return 0;return (--it)->second;}y6 max_weights(int n, int m, vector<int> x, vector<int> y,vector<int> w) {for (int i = 0; i < m; i++) {pos[++x[i]].push_back(++y[i]);p[x[i]].push_back({y[i], w[i]});}for (int i = 1; i <= n; i++){sort(p[i].begin(), p[i].end());sort(pos[i].begin(), pos[i].end());y6 sum = 0;for (auto& [j, c]: p[i]) {y6 t = sum;sum+=c;c+=t;}}for (int i = 1; i <= n; i++){vector <y6> ps = {0, n};for (auto j: pos[i-1]) ps.push_back(j);for (auto j: pos[i+1]) ps.push_back(j);sort(ps.begin(), ps.end());for (auto j: ps){auto it = lower_bound(suff[i-1].begin(), suff[i-1].end(), make_pair(j, -1ll));dp[i][j][0] = -psum(i, j);if (it != suff[i-1].end()) dp[i][j][0] += it->second;it = lower_bound(pref[i - 1].begin(), pref[i - 1].end(), make_pair(j, (y6) 1e18));dp[i][j][1] = ((i - 2 >= 0) ? mx[i-2]: 0) + psum(i-1, j);if (it != pref[i-1].begin()) dp[i][j][1] = max(dp[i][j][1], (--it)->second + psum(i-1, j));mx[i] = max({mx[i], dp[i][j][0], dp[i][j][1]});}for (auto j: ps) {pref[i].push_back(make_pair(j, max((pref[i].empty() ? 0ll: pref[i].back().second), dp[i][j][1] - psum(i, j))));}reverse(ps.begin(), ps.end());for (auto j: ps) {suff[i].push_back(make_pair(j, max((suff[i].empty() ? 0ll: suff[i].back().second), max(dp[i][j][0], dp[i][j][1]) + psum(i + 1, j))));}reverse(suff[i].begin(), suff[i].end());}return mx[n];}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
128 ms |
75284 KB |
Output is correct |
2 |
Correct |
145 ms |
80944 KB |
Output is correct |
3 |
Correct |
79 ms |
66712 KB |
Output is correct |
4 |
Correct |
80 ms |
66764 KB |
Output is correct |
5 |
Correct |
345 ms |
115348 KB |
Output is correct |
6 |
Correct |
503 ms |
126516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
37844 KB |
Output is correct |
2 |
Correct |
221 ms |
84780 KB |
Output is correct |
3 |
Correct |
252 ms |
91820 KB |
Output is correct |
4 |
Correct |
131 ms |
75436 KB |
Output is correct |
5 |
Correct |
143 ms |
80948 KB |
Output is correct |
6 |
Correct |
18 ms |
37832 KB |
Output is correct |
7 |
Correct |
23 ms |
37836 KB |
Output is correct |
8 |
Correct |
18 ms |
37880 KB |
Output is correct |
9 |
Correct |
18 ms |
37880 KB |
Output is correct |
10 |
Correct |
81 ms |
66828 KB |
Output is correct |
11 |
Correct |
82 ms |
66788 KB |
Output is correct |
12 |
Correct |
164 ms |
78448 KB |
Output is correct |
13 |
Correct |
156 ms |
84180 KB |
Output is correct |
14 |
Correct |
141 ms |
76860 KB |
Output is correct |
15 |
Correct |
162 ms |
78504 KB |
Output is correct |
16 |
Correct |
137 ms |
76836 KB |
Output is correct |
17 |
Correct |
147 ms |
81192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
66724 KB |
Output is correct |
2 |
Correct |
79 ms |
66764 KB |
Output is correct |
3 |
Correct |
138 ms |
79508 KB |
Output is correct |
4 |
Correct |
125 ms |
77516 KB |
Output is correct |
5 |
Correct |
200 ms |
94392 KB |
Output is correct |
6 |
Correct |
194 ms |
94128 KB |
Output is correct |
7 |
Correct |
197 ms |
94216 KB |
Output is correct |
8 |
Correct |
195 ms |
94144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
37844 KB |
Output is correct |
2 |
Correct |
17 ms |
37764 KB |
Output is correct |
3 |
Correct |
18 ms |
37844 KB |
Output is correct |
4 |
Correct |
19 ms |
37844 KB |
Output is correct |
5 |
Correct |
18 ms |
37844 KB |
Output is correct |
6 |
Correct |
18 ms |
37884 KB |
Output is correct |
7 |
Correct |
18 ms |
37868 KB |
Output is correct |
8 |
Correct |
18 ms |
37844 KB |
Output is correct |
9 |
Correct |
20 ms |
37972 KB |
Output is correct |
10 |
Correct |
22 ms |
38392 KB |
Output is correct |
11 |
Correct |
18 ms |
37988 KB |
Output is correct |
12 |
Correct |
19 ms |
38100 KB |
Output is correct |
13 |
Correct |
19 ms |
37888 KB |
Output is correct |
14 |
Correct |
19 ms |
38172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
37844 KB |
Output is correct |
2 |
Correct |
17 ms |
37764 KB |
Output is correct |
3 |
Correct |
18 ms |
37844 KB |
Output is correct |
4 |
Correct |
19 ms |
37844 KB |
Output is correct |
5 |
Correct |
18 ms |
37844 KB |
Output is correct |
6 |
Correct |
18 ms |
37884 KB |
Output is correct |
7 |
Correct |
18 ms |
37868 KB |
Output is correct |
8 |
Correct |
18 ms |
37844 KB |
Output is correct |
9 |
Correct |
20 ms |
37972 KB |
Output is correct |
10 |
Correct |
22 ms |
38392 KB |
Output is correct |
11 |
Correct |
18 ms |
37988 KB |
Output is correct |
12 |
Correct |
19 ms |
38100 KB |
Output is correct |
13 |
Correct |
19 ms |
37888 KB |
Output is correct |
14 |
Correct |
19 ms |
38172 KB |
Output is correct |
15 |
Correct |
19 ms |
37972 KB |
Output is correct |
16 |
Correct |
20 ms |
38192 KB |
Output is correct |
17 |
Correct |
67 ms |
43204 KB |
Output is correct |
18 |
Correct |
65 ms |
45256 KB |
Output is correct |
19 |
Correct |
59 ms |
45644 KB |
Output is correct |
20 |
Correct |
60 ms |
45672 KB |
Output is correct |
21 |
Correct |
62 ms |
45680 KB |
Output is correct |
22 |
Correct |
108 ms |
51936 KB |
Output is correct |
23 |
Correct |
30 ms |
39324 KB |
Output is correct |
24 |
Correct |
48 ms |
41956 KB |
Output is correct |
25 |
Correct |
21 ms |
38136 KB |
Output is correct |
26 |
Correct |
25 ms |
39136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
37844 KB |
Output is correct |
2 |
Correct |
17 ms |
37764 KB |
Output is correct |
3 |
Correct |
18 ms |
37844 KB |
Output is correct |
4 |
Correct |
19 ms |
37844 KB |
Output is correct |
5 |
Correct |
18 ms |
37844 KB |
Output is correct |
6 |
Correct |
18 ms |
37884 KB |
Output is correct |
7 |
Correct |
18 ms |
37868 KB |
Output is correct |
8 |
Correct |
18 ms |
37844 KB |
Output is correct |
9 |
Correct |
20 ms |
37972 KB |
Output is correct |
10 |
Correct |
22 ms |
38392 KB |
Output is correct |
11 |
Correct |
18 ms |
37988 KB |
Output is correct |
12 |
Correct |
19 ms |
38100 KB |
Output is correct |
13 |
Correct |
19 ms |
37888 KB |
Output is correct |
14 |
Correct |
19 ms |
38172 KB |
Output is correct |
15 |
Correct |
19 ms |
37972 KB |
Output is correct |
16 |
Correct |
20 ms |
38192 KB |
Output is correct |
17 |
Correct |
67 ms |
43204 KB |
Output is correct |
18 |
Correct |
65 ms |
45256 KB |
Output is correct |
19 |
Correct |
59 ms |
45644 KB |
Output is correct |
20 |
Correct |
60 ms |
45672 KB |
Output is correct |
21 |
Correct |
62 ms |
45680 KB |
Output is correct |
22 |
Correct |
108 ms |
51936 KB |
Output is correct |
23 |
Correct |
30 ms |
39324 KB |
Output is correct |
24 |
Correct |
48 ms |
41956 KB |
Output is correct |
25 |
Correct |
21 ms |
38136 KB |
Output is correct |
26 |
Correct |
25 ms |
39136 KB |
Output is correct |
27 |
Correct |
23 ms |
39508 KB |
Output is correct |
28 |
Correct |
253 ms |
67888 KB |
Output is correct |
29 |
Correct |
345 ms |
76348 KB |
Output is correct |
30 |
Correct |
314 ms |
79520 KB |
Output is correct |
31 |
Correct |
320 ms |
79460 KB |
Output is correct |
32 |
Correct |
337 ms |
80592 KB |
Output is correct |
33 |
Correct |
322 ms |
79500 KB |
Output is correct |
34 |
Correct |
326 ms |
79292 KB |
Output is correct |
35 |
Correct |
136 ms |
57116 KB |
Output is correct |
36 |
Correct |
346 ms |
82384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
66724 KB |
Output is correct |
2 |
Correct |
79 ms |
66764 KB |
Output is correct |
3 |
Correct |
138 ms |
79508 KB |
Output is correct |
4 |
Correct |
125 ms |
77516 KB |
Output is correct |
5 |
Correct |
200 ms |
94392 KB |
Output is correct |
6 |
Correct |
194 ms |
94128 KB |
Output is correct |
7 |
Correct |
197 ms |
94216 KB |
Output is correct |
8 |
Correct |
195 ms |
94144 KB |
Output is correct |
9 |
Correct |
219 ms |
94160 KB |
Output is correct |
10 |
Correct |
150 ms |
74644 KB |
Output is correct |
11 |
Correct |
289 ms |
111508 KB |
Output is correct |
12 |
Correct |
18 ms |
37844 KB |
Output is correct |
13 |
Correct |
19 ms |
37844 KB |
Output is correct |
14 |
Correct |
18 ms |
37856 KB |
Output is correct |
15 |
Correct |
18 ms |
37884 KB |
Output is correct |
16 |
Correct |
18 ms |
37824 KB |
Output is correct |
17 |
Correct |
19 ms |
37864 KB |
Output is correct |
18 |
Correct |
79 ms |
66824 KB |
Output is correct |
19 |
Correct |
78 ms |
66764 KB |
Output is correct |
20 |
Correct |
79 ms |
66828 KB |
Output is correct |
21 |
Correct |
79 ms |
66800 KB |
Output is correct |
22 |
Correct |
244 ms |
92108 KB |
Output is correct |
23 |
Correct |
322 ms |
110900 KB |
Output is correct |
24 |
Correct |
313 ms |
110796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
128 ms |
75284 KB |
Output is correct |
2 |
Correct |
145 ms |
80944 KB |
Output is correct |
3 |
Correct |
79 ms |
66712 KB |
Output is correct |
4 |
Correct |
80 ms |
66764 KB |
Output is correct |
5 |
Correct |
345 ms |
115348 KB |
Output is correct |
6 |
Correct |
503 ms |
126516 KB |
Output is correct |
7 |
Correct |
19 ms |
37844 KB |
Output is correct |
8 |
Correct |
221 ms |
84780 KB |
Output is correct |
9 |
Correct |
252 ms |
91820 KB |
Output is correct |
10 |
Correct |
131 ms |
75436 KB |
Output is correct |
11 |
Correct |
143 ms |
80948 KB |
Output is correct |
12 |
Correct |
18 ms |
37832 KB |
Output is correct |
13 |
Correct |
23 ms |
37836 KB |
Output is correct |
14 |
Correct |
18 ms |
37880 KB |
Output is correct |
15 |
Correct |
18 ms |
37880 KB |
Output is correct |
16 |
Correct |
81 ms |
66828 KB |
Output is correct |
17 |
Correct |
82 ms |
66788 KB |
Output is correct |
18 |
Correct |
164 ms |
78448 KB |
Output is correct |
19 |
Correct |
156 ms |
84180 KB |
Output is correct |
20 |
Correct |
141 ms |
76860 KB |
Output is correct |
21 |
Correct |
162 ms |
78504 KB |
Output is correct |
22 |
Correct |
137 ms |
76836 KB |
Output is correct |
23 |
Correct |
147 ms |
81192 KB |
Output is correct |
24 |
Correct |
80 ms |
66724 KB |
Output is correct |
25 |
Correct |
79 ms |
66764 KB |
Output is correct |
26 |
Correct |
138 ms |
79508 KB |
Output is correct |
27 |
Correct |
125 ms |
77516 KB |
Output is correct |
28 |
Correct |
200 ms |
94392 KB |
Output is correct |
29 |
Correct |
194 ms |
94128 KB |
Output is correct |
30 |
Correct |
197 ms |
94216 KB |
Output is correct |
31 |
Correct |
195 ms |
94144 KB |
Output is correct |
32 |
Correct |
17 ms |
37844 KB |
Output is correct |
33 |
Correct |
17 ms |
37764 KB |
Output is correct |
34 |
Correct |
18 ms |
37844 KB |
Output is correct |
35 |
Correct |
19 ms |
37844 KB |
Output is correct |
36 |
Correct |
18 ms |
37844 KB |
Output is correct |
37 |
Correct |
18 ms |
37884 KB |
Output is correct |
38 |
Correct |
18 ms |
37868 KB |
Output is correct |
39 |
Correct |
18 ms |
37844 KB |
Output is correct |
40 |
Correct |
20 ms |
37972 KB |
Output is correct |
41 |
Correct |
22 ms |
38392 KB |
Output is correct |
42 |
Correct |
18 ms |
37988 KB |
Output is correct |
43 |
Correct |
19 ms |
38100 KB |
Output is correct |
44 |
Correct |
19 ms |
37888 KB |
Output is correct |
45 |
Correct |
19 ms |
38172 KB |
Output is correct |
46 |
Correct |
19 ms |
37972 KB |
Output is correct |
47 |
Correct |
20 ms |
38192 KB |
Output is correct |
48 |
Correct |
67 ms |
43204 KB |
Output is correct |
49 |
Correct |
65 ms |
45256 KB |
Output is correct |
50 |
Correct |
59 ms |
45644 KB |
Output is correct |
51 |
Correct |
60 ms |
45672 KB |
Output is correct |
52 |
Correct |
62 ms |
45680 KB |
Output is correct |
53 |
Correct |
108 ms |
51936 KB |
Output is correct |
54 |
Correct |
30 ms |
39324 KB |
Output is correct |
55 |
Correct |
48 ms |
41956 KB |
Output is correct |
56 |
Correct |
21 ms |
38136 KB |
Output is correct |
57 |
Correct |
25 ms |
39136 KB |
Output is correct |
58 |
Correct |
23 ms |
39508 KB |
Output is correct |
59 |
Correct |
253 ms |
67888 KB |
Output is correct |
60 |
Correct |
345 ms |
76348 KB |
Output is correct |
61 |
Correct |
314 ms |
79520 KB |
Output is correct |
62 |
Correct |
320 ms |
79460 KB |
Output is correct |
63 |
Correct |
337 ms |
80592 KB |
Output is correct |
64 |
Correct |
322 ms |
79500 KB |
Output is correct |
65 |
Correct |
326 ms |
79292 KB |
Output is correct |
66 |
Correct |
136 ms |
57116 KB |
Output is correct |
67 |
Correct |
346 ms |
82384 KB |
Output is correct |
68 |
Correct |
219 ms |
94160 KB |
Output is correct |
69 |
Correct |
150 ms |
74644 KB |
Output is correct |
70 |
Correct |
289 ms |
111508 KB |
Output is correct |
71 |
Correct |
18 ms |
37844 KB |
Output is correct |
72 |
Correct |
19 ms |
37844 KB |
Output is correct |
73 |
Correct |
18 ms |
37856 KB |
Output is correct |
74 |
Correct |
18 ms |
37884 KB |
Output is correct |
75 |
Correct |
18 ms |
37824 KB |
Output is correct |
76 |
Correct |
19 ms |
37864 KB |
Output is correct |
77 |
Correct |
79 ms |
66824 KB |
Output is correct |
78 |
Correct |
78 ms |
66764 KB |
Output is correct |
79 |
Correct |
79 ms |
66828 KB |
Output is correct |
80 |
Correct |
79 ms |
66800 KB |
Output is correct |
81 |
Correct |
244 ms |
92108 KB |
Output is correct |
82 |
Correct |
322 ms |
110900 KB |
Output is correct |
83 |
Correct |
313 ms |
110796 KB |
Output is correct |
84 |
Correct |
493 ms |
104824 KB |
Output is correct |
85 |
Correct |
540 ms |
106852 KB |
Output is correct |
86 |
Correct |
522 ms |
124432 KB |
Output is correct |
87 |
Correct |
526 ms |
129372 KB |
Output is correct |
88 |
Correct |
18 ms |
37856 KB |
Output is correct |
89 |
Correct |
564 ms |
128932 KB |
Output is correct |
90 |
Correct |
417 ms |
118072 KB |
Output is correct |
91 |
Correct |
387 ms |
115304 KB |
Output is correct |