#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
const int maxn = 2e5 + 2;
map <int64, int64> dp [maxn][2];
int64 mx [maxn];
vector <pair <int64, int64> > p[maxn];
vector <pair <int64, int64> > pref [maxn], suff[maxn];
vector <int64> pos [maxn];
int64 psum (int64 i, int64 j) {
auto it = lower_bound(p[i].begin(), p[i].end(), make_pair(j, (int64) 1e18));
if (it == p[i].begin()) return 0;
return (--it)->second;
}
int64 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());
int64 sum = 0;
for (auto& [j, c]: p[i]) {
int64 t = sum;
sum+=c;
c+=t;
// cout << i << " " << j << " " << c << "\n";
}
}
// cout << "> " << psum(1, 3) << " " << psum(1, 5) << " " << psum(1, 2) << "\n";
for (int i = 1; i <= n; i++){
vector <int64> 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;
// dp[i][j][0] = suff[i-1][j] - p[i][j];
it = lower_bound(pref[i - 1].begin(), pref[i - 1].end(), make_pair(j, (int64) 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));
// dp[i][j][1] = max(mx[i-2] + p[i-1][j], pref[i-1][j] + p[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(pos[i].begin(), pos[i].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());
// for (int j = 0; j <= n; j++){
// pref[i][j] = max((j != 0 ? pref[i][j - 1]: 0ll), dp[i][j][1] - p[i][j]);
// }
// for (int j = n; j >= 0; j--){
// suff[i][j] = max((j != n ? suff[i][j + 1] : 0ll), max(dp[i][j][0], dp[i][j][1]) + p[i + 1][j]);
// }
}
return mx[n];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
124 ms |
75280 KB |
Output is correct |
2 |
Correct |
149 ms |
80892 KB |
Output is correct |
3 |
Correct |
81 ms |
66816 KB |
Output is correct |
4 |
Correct |
77 ms |
66764 KB |
Output is correct |
5 |
Correct |
344 ms |
115360 KB |
Output is correct |
6 |
Correct |
508 ms |
126508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
37844 KB |
Output is correct |
2 |
Correct |
224 ms |
84740 KB |
Output is correct |
3 |
Correct |
250 ms |
91928 KB |
Output is correct |
4 |
Correct |
126 ms |
75256 KB |
Output is correct |
5 |
Correct |
146 ms |
80900 KB |
Output is correct |
6 |
Correct |
22 ms |
37844 KB |
Output is correct |
7 |
Correct |
19 ms |
37844 KB |
Output is correct |
8 |
Correct |
18 ms |
37848 KB |
Output is correct |
9 |
Correct |
17 ms |
37808 KB |
Output is correct |
10 |
Correct |
81 ms |
66852 KB |
Output is correct |
11 |
Correct |
79 ms |
66760 KB |
Output is correct |
12 |
Correct |
140 ms |
78412 KB |
Output is correct |
13 |
Correct |
161 ms |
83988 KB |
Output is correct |
14 |
Correct |
138 ms |
76816 KB |
Output is correct |
15 |
Correct |
156 ms |
78500 KB |
Output is correct |
16 |
Correct |
145 ms |
76824 KB |
Output is correct |
17 |
Correct |
151 ms |
81132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
66828 KB |
Output is correct |
2 |
Correct |
83 ms |
66824 KB |
Output is correct |
3 |
Correct |
150 ms |
79468 KB |
Output is correct |
4 |
Correct |
131 ms |
77552 KB |
Output is correct |
5 |
Correct |
201 ms |
94236 KB |
Output is correct |
6 |
Correct |
197 ms |
94236 KB |
Output is correct |
7 |
Correct |
201 ms |
94216 KB |
Output is correct |
8 |
Correct |
206 ms |
94200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
37872 KB |
Output is correct |
2 |
Correct |
20 ms |
37840 KB |
Output is correct |
3 |
Correct |
18 ms |
37768 KB |
Output is correct |
4 |
Correct |
20 ms |
37844 KB |
Output is correct |
5 |
Correct |
19 ms |
37860 KB |
Output is correct |
6 |
Correct |
19 ms |
37884 KB |
Output is correct |
7 |
Correct |
20 ms |
37884 KB |
Output is correct |
8 |
Correct |
18 ms |
37876 KB |
Output is correct |
9 |
Correct |
18 ms |
37972 KB |
Output is correct |
10 |
Incorrect |
20 ms |
38292 KB |
1st lines differ - on the 1st token, expected: '799839985182', found: '799745076036' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
37872 KB |
Output is correct |
2 |
Correct |
20 ms |
37840 KB |
Output is correct |
3 |
Correct |
18 ms |
37768 KB |
Output is correct |
4 |
Correct |
20 ms |
37844 KB |
Output is correct |
5 |
Correct |
19 ms |
37860 KB |
Output is correct |
6 |
Correct |
19 ms |
37884 KB |
Output is correct |
7 |
Correct |
20 ms |
37884 KB |
Output is correct |
8 |
Correct |
18 ms |
37876 KB |
Output is correct |
9 |
Correct |
18 ms |
37972 KB |
Output is correct |
10 |
Incorrect |
20 ms |
38292 KB |
1st lines differ - on the 1st token, expected: '799839985182', found: '799745076036' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
37872 KB |
Output is correct |
2 |
Correct |
20 ms |
37840 KB |
Output is correct |
3 |
Correct |
18 ms |
37768 KB |
Output is correct |
4 |
Correct |
20 ms |
37844 KB |
Output is correct |
5 |
Correct |
19 ms |
37860 KB |
Output is correct |
6 |
Correct |
19 ms |
37884 KB |
Output is correct |
7 |
Correct |
20 ms |
37884 KB |
Output is correct |
8 |
Correct |
18 ms |
37876 KB |
Output is correct |
9 |
Correct |
18 ms |
37972 KB |
Output is correct |
10 |
Incorrect |
20 ms |
38292 KB |
1st lines differ - on the 1st token, expected: '799839985182', found: '799745076036' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
81 ms |
66828 KB |
Output is correct |
2 |
Correct |
83 ms |
66824 KB |
Output is correct |
3 |
Correct |
150 ms |
79468 KB |
Output is correct |
4 |
Correct |
131 ms |
77552 KB |
Output is correct |
5 |
Correct |
201 ms |
94236 KB |
Output is correct |
6 |
Correct |
197 ms |
94236 KB |
Output is correct |
7 |
Correct |
201 ms |
94216 KB |
Output is correct |
8 |
Correct |
206 ms |
94200 KB |
Output is correct |
9 |
Correct |
218 ms |
94224 KB |
Output is correct |
10 |
Correct |
155 ms |
74616 KB |
Output is correct |
11 |
Correct |
297 ms |
111548 KB |
Output is correct |
12 |
Correct |
18 ms |
37844 KB |
Output is correct |
13 |
Correct |
18 ms |
37844 KB |
Output is correct |
14 |
Correct |
18 ms |
37880 KB |
Output is correct |
15 |
Correct |
20 ms |
37868 KB |
Output is correct |
16 |
Correct |
19 ms |
37844 KB |
Output is correct |
17 |
Correct |
18 ms |
37840 KB |
Output is correct |
18 |
Correct |
97 ms |
66804 KB |
Output is correct |
19 |
Correct |
79 ms |
66788 KB |
Output is correct |
20 |
Correct |
84 ms |
66772 KB |
Output is correct |
21 |
Correct |
81 ms |
66764 KB |
Output is correct |
22 |
Incorrect |
251 ms |
92144 KB |
1st lines differ - on the 1st token, expected: '45561826463480', found: '45319947198848' |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
124 ms |
75280 KB |
Output is correct |
2 |
Correct |
149 ms |
80892 KB |
Output is correct |
3 |
Correct |
81 ms |
66816 KB |
Output is correct |
4 |
Correct |
77 ms |
66764 KB |
Output is correct |
5 |
Correct |
344 ms |
115360 KB |
Output is correct |
6 |
Correct |
508 ms |
126508 KB |
Output is correct |
7 |
Correct |
18 ms |
37844 KB |
Output is correct |
8 |
Correct |
224 ms |
84740 KB |
Output is correct |
9 |
Correct |
250 ms |
91928 KB |
Output is correct |
10 |
Correct |
126 ms |
75256 KB |
Output is correct |
11 |
Correct |
146 ms |
80900 KB |
Output is correct |
12 |
Correct |
22 ms |
37844 KB |
Output is correct |
13 |
Correct |
19 ms |
37844 KB |
Output is correct |
14 |
Correct |
18 ms |
37848 KB |
Output is correct |
15 |
Correct |
17 ms |
37808 KB |
Output is correct |
16 |
Correct |
81 ms |
66852 KB |
Output is correct |
17 |
Correct |
79 ms |
66760 KB |
Output is correct |
18 |
Correct |
140 ms |
78412 KB |
Output is correct |
19 |
Correct |
161 ms |
83988 KB |
Output is correct |
20 |
Correct |
138 ms |
76816 KB |
Output is correct |
21 |
Correct |
156 ms |
78500 KB |
Output is correct |
22 |
Correct |
145 ms |
76824 KB |
Output is correct |
23 |
Correct |
151 ms |
81132 KB |
Output is correct |
24 |
Correct |
81 ms |
66828 KB |
Output is correct |
25 |
Correct |
83 ms |
66824 KB |
Output is correct |
26 |
Correct |
150 ms |
79468 KB |
Output is correct |
27 |
Correct |
131 ms |
77552 KB |
Output is correct |
28 |
Correct |
201 ms |
94236 KB |
Output is correct |
29 |
Correct |
197 ms |
94236 KB |
Output is correct |
30 |
Correct |
201 ms |
94216 KB |
Output is correct |
31 |
Correct |
206 ms |
94200 KB |
Output is correct |
32 |
Correct |
18 ms |
37872 KB |
Output is correct |
33 |
Correct |
20 ms |
37840 KB |
Output is correct |
34 |
Correct |
18 ms |
37768 KB |
Output is correct |
35 |
Correct |
20 ms |
37844 KB |
Output is correct |
36 |
Correct |
19 ms |
37860 KB |
Output is correct |
37 |
Correct |
19 ms |
37884 KB |
Output is correct |
38 |
Correct |
20 ms |
37884 KB |
Output is correct |
39 |
Correct |
18 ms |
37876 KB |
Output is correct |
40 |
Correct |
18 ms |
37972 KB |
Output is correct |
41 |
Incorrect |
20 ms |
38292 KB |
1st lines differ - on the 1st token, expected: '799839985182', found: '799745076036' |
42 |
Halted |
0 ms |
0 KB |
- |