#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].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 |
135 ms |
76292 KB |
Output is correct |
2 |
Correct |
147 ms |
82372 KB |
Output is correct |
3 |
Correct |
87 ms |
66812 KB |
Output is correct |
4 |
Correct |
83 ms |
66824 KB |
Output is correct |
5 |
Correct |
349 ms |
121308 KB |
Output is correct |
6 |
Correct |
511 ms |
133064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
37844 KB |
Output is correct |
2 |
Correct |
215 ms |
85824 KB |
Output is correct |
3 |
Correct |
251 ms |
95140 KB |
Output is correct |
4 |
Correct |
163 ms |
76392 KB |
Output is correct |
5 |
Correct |
147 ms |
82408 KB |
Output is correct |
6 |
Correct |
21 ms |
37844 KB |
Output is correct |
7 |
Correct |
19 ms |
37784 KB |
Output is correct |
8 |
Correct |
19 ms |
37880 KB |
Output is correct |
9 |
Correct |
21 ms |
37804 KB |
Output is correct |
10 |
Correct |
82 ms |
66744 KB |
Output is correct |
11 |
Correct |
85 ms |
66768 KB |
Output is correct |
12 |
Correct |
137 ms |
79556 KB |
Output is correct |
13 |
Correct |
153 ms |
85516 KB |
Output is correct |
14 |
Correct |
137 ms |
78032 KB |
Output is correct |
15 |
Correct |
163 ms |
79764 KB |
Output is correct |
16 |
Correct |
135 ms |
78052 KB |
Output is correct |
17 |
Correct |
148 ms |
82492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
66892 KB |
Output is correct |
2 |
Correct |
79 ms |
66756 KB |
Output is correct |
3 |
Correct |
141 ms |
80164 KB |
Output is correct |
4 |
Correct |
126 ms |
77756 KB |
Output is correct |
5 |
Correct |
197 ms |
94264 KB |
Output is correct |
6 |
Correct |
196 ms |
95000 KB |
Output is correct |
7 |
Correct |
197 ms |
95464 KB |
Output is correct |
8 |
Correct |
195 ms |
95552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
37844 KB |
Output is correct |
2 |
Correct |
19 ms |
37792 KB |
Output is correct |
3 |
Correct |
19 ms |
37776 KB |
Output is correct |
4 |
Correct |
18 ms |
37844 KB |
Output is correct |
5 |
Correct |
18 ms |
37844 KB |
Output is correct |
6 |
Correct |
19 ms |
37844 KB |
Output is correct |
7 |
Correct |
18 ms |
37844 KB |
Output is correct |
8 |
Correct |
19 ms |
37828 KB |
Output is correct |
9 |
Correct |
19 ms |
37976 KB |
Output is correct |
10 |
Incorrect |
19 ms |
38356 KB |
1st lines differ - on the 1st token, expected: '799839985182', found: '799745076036' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
37844 KB |
Output is correct |
2 |
Correct |
19 ms |
37792 KB |
Output is correct |
3 |
Correct |
19 ms |
37776 KB |
Output is correct |
4 |
Correct |
18 ms |
37844 KB |
Output is correct |
5 |
Correct |
18 ms |
37844 KB |
Output is correct |
6 |
Correct |
19 ms |
37844 KB |
Output is correct |
7 |
Correct |
18 ms |
37844 KB |
Output is correct |
8 |
Correct |
19 ms |
37828 KB |
Output is correct |
9 |
Correct |
19 ms |
37976 KB |
Output is correct |
10 |
Incorrect |
19 ms |
38356 KB |
1st lines differ - on the 1st token, expected: '799839985182', found: '799745076036' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
37844 KB |
Output is correct |
2 |
Correct |
19 ms |
37792 KB |
Output is correct |
3 |
Correct |
19 ms |
37776 KB |
Output is correct |
4 |
Correct |
18 ms |
37844 KB |
Output is correct |
5 |
Correct |
18 ms |
37844 KB |
Output is correct |
6 |
Correct |
19 ms |
37844 KB |
Output is correct |
7 |
Correct |
18 ms |
37844 KB |
Output is correct |
8 |
Correct |
19 ms |
37828 KB |
Output is correct |
9 |
Correct |
19 ms |
37976 KB |
Output is correct |
10 |
Incorrect |
19 ms |
38356 KB |
1st lines differ - on the 1st token, expected: '799839985182', found: '799745076036' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
66892 KB |
Output is correct |
2 |
Correct |
79 ms |
66756 KB |
Output is correct |
3 |
Correct |
141 ms |
80164 KB |
Output is correct |
4 |
Correct |
126 ms |
77756 KB |
Output is correct |
5 |
Correct |
197 ms |
94264 KB |
Output is correct |
6 |
Correct |
196 ms |
95000 KB |
Output is correct |
7 |
Correct |
197 ms |
95464 KB |
Output is correct |
8 |
Correct |
195 ms |
95552 KB |
Output is correct |
9 |
Correct |
217 ms |
94876 KB |
Output is correct |
10 |
Correct |
168 ms |
75688 KB |
Output is correct |
11 |
Correct |
284 ms |
114080 KB |
Output is correct |
12 |
Correct |
18 ms |
37844 KB |
Output is correct |
13 |
Correct |
18 ms |
37880 KB |
Output is correct |
14 |
Correct |
20 ms |
37840 KB |
Output is correct |
15 |
Correct |
18 ms |
37844 KB |
Output is correct |
16 |
Correct |
18 ms |
37804 KB |
Output is correct |
17 |
Correct |
19 ms |
37852 KB |
Output is correct |
18 |
Correct |
81 ms |
66912 KB |
Output is correct |
19 |
Correct |
79 ms |
66720 KB |
Output is correct |
20 |
Correct |
79 ms |
66720 KB |
Output is correct |
21 |
Correct |
82 ms |
66856 KB |
Output is correct |
22 |
Incorrect |
257 ms |
93524 KB |
1st lines differ - on the 1st token, expected: '45561826463480', found: '45319947198848' |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
135 ms |
76292 KB |
Output is correct |
2 |
Correct |
147 ms |
82372 KB |
Output is correct |
3 |
Correct |
87 ms |
66812 KB |
Output is correct |
4 |
Correct |
83 ms |
66824 KB |
Output is correct |
5 |
Correct |
349 ms |
121308 KB |
Output is correct |
6 |
Correct |
511 ms |
133064 KB |
Output is correct |
7 |
Correct |
20 ms |
37844 KB |
Output is correct |
8 |
Correct |
215 ms |
85824 KB |
Output is correct |
9 |
Correct |
251 ms |
95140 KB |
Output is correct |
10 |
Correct |
163 ms |
76392 KB |
Output is correct |
11 |
Correct |
147 ms |
82408 KB |
Output is correct |
12 |
Correct |
21 ms |
37844 KB |
Output is correct |
13 |
Correct |
19 ms |
37784 KB |
Output is correct |
14 |
Correct |
19 ms |
37880 KB |
Output is correct |
15 |
Correct |
21 ms |
37804 KB |
Output is correct |
16 |
Correct |
82 ms |
66744 KB |
Output is correct |
17 |
Correct |
85 ms |
66768 KB |
Output is correct |
18 |
Correct |
137 ms |
79556 KB |
Output is correct |
19 |
Correct |
153 ms |
85516 KB |
Output is correct |
20 |
Correct |
137 ms |
78032 KB |
Output is correct |
21 |
Correct |
163 ms |
79764 KB |
Output is correct |
22 |
Correct |
135 ms |
78052 KB |
Output is correct |
23 |
Correct |
148 ms |
82492 KB |
Output is correct |
24 |
Correct |
80 ms |
66892 KB |
Output is correct |
25 |
Correct |
79 ms |
66756 KB |
Output is correct |
26 |
Correct |
141 ms |
80164 KB |
Output is correct |
27 |
Correct |
126 ms |
77756 KB |
Output is correct |
28 |
Correct |
197 ms |
94264 KB |
Output is correct |
29 |
Correct |
196 ms |
95000 KB |
Output is correct |
30 |
Correct |
197 ms |
95464 KB |
Output is correct |
31 |
Correct |
195 ms |
95552 KB |
Output is correct |
32 |
Correct |
18 ms |
37844 KB |
Output is correct |
33 |
Correct |
19 ms |
37792 KB |
Output is correct |
34 |
Correct |
19 ms |
37776 KB |
Output is correct |
35 |
Correct |
18 ms |
37844 KB |
Output is correct |
36 |
Correct |
18 ms |
37844 KB |
Output is correct |
37 |
Correct |
19 ms |
37844 KB |
Output is correct |
38 |
Correct |
18 ms |
37844 KB |
Output is correct |
39 |
Correct |
19 ms |
37828 KB |
Output is correct |
40 |
Correct |
19 ms |
37976 KB |
Output is correct |
41 |
Incorrect |
19 ms |
38356 KB |
1st lines differ - on the 1st token, expected: '799839985182', found: '799745076036' |
42 |
Halted |
0 ms |
0 KB |
- |