#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]);
re = max(re, DP_tot[i]);
}
return re;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
8652 KB |
Output is correct |
2 |
Correct |
32 ms |
9928 KB |
Output is correct |
3 |
Correct |
3 ms |
6488 KB |
Output is correct |
4 |
Correct |
3 ms |
6492 KB |
Output is correct |
5 |
Incorrect |
104 ms |
16344 KB |
1st lines differ - on the 1st token, expected: '149814460735479', found: '90001997297150' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
71 ms |
14056 KB |
Output is correct |
3 |
Correct |
66 ms |
16588 KB |
Output is correct |
4 |
Correct |
26 ms |
9928 KB |
Output is correct |
5 |
Correct |
32 ms |
11576 KB |
Output is correct |
6 |
Correct |
0 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
4 ms |
6492 KB |
Output is correct |
11 |
Correct |
5 ms |
6492 KB |
Output is correct |
12 |
Correct |
32 ms |
10012 KB |
Output is correct |
13 |
Correct |
41 ms |
11464 KB |
Output is correct |
14 |
Correct |
29 ms |
10084 KB |
Output is correct |
15 |
Correct |
42 ms |
11344 KB |
Output is correct |
16 |
Correct |
29 ms |
10192 KB |
Output is correct |
17 |
Correct |
34 ms |
11204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
6492 KB |
Output is correct |
2 |
Correct |
3 ms |
6492 KB |
Output is correct |
3 |
Incorrect |
23 ms |
8868 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '138955760564' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
1 ms |
604 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '194343694717' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
1 ms |
604 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '194343694717' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
1 ms |
604 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 |
3 ms |
6492 KB |
Output is correct |
3 |
Incorrect |
23 ms |
8868 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '138955760564' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
8652 KB |
Output is correct |
2 |
Correct |
32 ms |
9928 KB |
Output is correct |
3 |
Correct |
3 ms |
6488 KB |
Output is correct |
4 |
Correct |
3 ms |
6492 KB |
Output is correct |
5 |
Incorrect |
104 ms |
16344 KB |
1st lines differ - on the 1st token, expected: '149814460735479', found: '90001997297150' |
6 |
Halted |
0 ms |
0 KB |
- |