#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vll = vector<ll>;
struct AIB {
int n;
bool rev;
vll V;
AIB(int N, bool RV) : n(N + 1), rev(RV), V(N + 1, 0) {}
void update(int p, ll v) {
if(rev) p = n - p - 1;
++p;
while(p < n) {
V[p] = max(V[p], v);
p += p & -p;
}
}
ll query(int p) {
if(rev) p = n - p - 1;
++p;
ll re = 0;
while(p) {
re = max(re, V[p]);
p -= p & -p;
}
return re;
}
};
ll max_weights(int n, int m, vi X, vi Y, vi W) {
vector<vector<ii> > A(n);
for(int i = 0; i < m; ++i)
A[X[i]].push_back({Y[i], W[i]});
for(int i = 0; i < n; ++i) {
sort(A[i].begin(), A[i].end());
}
vll DP_tot(n, 0), DP0(n, 0), DP1(n, 0);
AIB MaPre(n, 0), MaSuf(n, 1);
ll re = 0;
for(int i = 0; i < n; ++i) {
ll rez_min = 0;
if(i > 1) rez_min = DP_tot[i - 2];
if(i + 1 < n) {
for(auto [y, w] : A[i]) { /// urcam, facem 0
ll re0 = rez_min;
if(MaPre.query(y - 1) > re0) re0 = MaPre.query(y - 1);
re0 += w;
MaPre.update(y, re0);
DP0[i] = max(DP0[i], re0);
}
}
reverse(A[i].begin(), A[i].end());
if(i) {
for(auto [y, w] : A[i]) {
ll re1 = rez_min;
if(MaSuf.query(y + 1) > re1) re1 = MaSuf.query(y + 1);
re1 += w;
MaSuf.update(y, re1);
MaPre.update(y, re1);
DP1[i] = max(DP1[i], re1);
}
}
DP_tot[i] = max(DP0[i], DP1[i]);
if(i) DP_tot[i] = max(DP_tot[i], DP_tot[i - 1]);
re = max(re, DP_tot[i]);
}
return re;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
8648 KB |
Output is correct |
2 |
Correct |
52 ms |
9920 KB |
Output is correct |
3 |
Correct |
4 ms |
6492 KB |
Output is correct |
4 |
Correct |
3 ms |
6492 KB |
Output is correct |
5 |
Correct |
104 ms |
16348 KB |
Output is correct |
6 |
Correct |
115 ms |
24656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
53 ms |
11192 KB |
Output is correct |
3 |
Correct |
64 ms |
12996 KB |
Output is correct |
4 |
Correct |
43 ms |
8644 KB |
Output is correct |
5 |
Correct |
31 ms |
9928 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
6492 KB |
Output is correct |
11 |
Correct |
3 ms |
6488 KB |
Output is correct |
12 |
Correct |
45 ms |
8668 KB |
Output is correct |
13 |
Correct |
36 ms |
9860 KB |
Output is correct |
14 |
Correct |
44 ms |
8552 KB |
Output is correct |
15 |
Correct |
29 ms |
9680 KB |
Output is correct |
16 |
Correct |
31 ms |
8644 KB |
Output is correct |
17 |
Correct |
48 ms |
9736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6492 KB |
Output is correct |
2 |
Correct |
4 ms |
6488 KB |
Output is correct |
3 |
Incorrect |
21 ms |
8796 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '16359027219341' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
440 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '194343694717' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
440 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '194343694717' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
440 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '194343694717' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6492 KB |
Output is correct |
2 |
Correct |
4 ms |
6488 KB |
Output is correct |
3 |
Incorrect |
21 ms |
8796 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '16359027219341' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
8648 KB |
Output is correct |
2 |
Correct |
52 ms |
9920 KB |
Output is correct |
3 |
Correct |
4 ms |
6492 KB |
Output is correct |
4 |
Correct |
3 ms |
6492 KB |
Output is correct |
5 |
Correct |
104 ms |
16348 KB |
Output is correct |
6 |
Correct |
115 ms |
24656 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
53 ms |
11192 KB |
Output is correct |
9 |
Correct |
64 ms |
12996 KB |
Output is correct |
10 |
Correct |
43 ms |
8644 KB |
Output is correct |
11 |
Correct |
31 ms |
9928 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
6492 KB |
Output is correct |
17 |
Correct |
3 ms |
6488 KB |
Output is correct |
18 |
Correct |
45 ms |
8668 KB |
Output is correct |
19 |
Correct |
36 ms |
9860 KB |
Output is correct |
20 |
Correct |
44 ms |
8552 KB |
Output is correct |
21 |
Correct |
29 ms |
9680 KB |
Output is correct |
22 |
Correct |
31 ms |
8644 KB |
Output is correct |
23 |
Correct |
48 ms |
9736 KB |
Output is correct |
24 |
Correct |
3 ms |
6492 KB |
Output is correct |
25 |
Correct |
4 ms |
6488 KB |
Output is correct |
26 |
Incorrect |
21 ms |
8796 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '16359027219341' |
27 |
Halted |
0 ms |
0 KB |
- |