#include <bits/stdc++.h>
#include "fish.h"
using namespace std;
typedef long long ll;
const ll INF = 1e18;
ll max_weights(int N, int M, vector <int> x, vector <int> y, vector <int> w) {
for (auto &it : x)
it++;
vector <ll> sum(N + 2);
vector <map <int, ll>> diff(N + 2);
for (int i = 0; i < M; i++) {
sum[x[i]] += w[i];
diff[x[i] + 1][y[i]] += w[i];
diff[x[i]][y[i]] -= w[i];
}
vector <ll> dp(5, -INF);
dp[0] = dp[1] = 0;
for (int i = 1; i <= N + 1; i++) {
auto update = [&](ll &ref, ll val) {
if (val > ref)
ref = val;
};
ll curr = 0;
vector <ll> trans(5);
trans[2] = sum[i - 1];
trans[3] = sum[i];
for (auto it : diff[i]) {
curr += it.second;
update(trans[1], curr);
update(trans[4], -curr);
}
vector <ll> nxt(5, -INF);
for (int j = 0; j < 5; j++) {
update(nxt[j], dp[(j + 4) % 5]);
if (j == 1 || j == 4)
update(nxt[j], dp[j]);
nxt[j] += trans[j];
}
dp = nxt;
}
return max({dp[0], dp[3], dp[4], 0ll});
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
137 ms |
17192 KB |
Output is correct |
2 |
Correct |
151 ms |
20560 KB |
Output is correct |
3 |
Correct |
7 ms |
5716 KB |
Output is correct |
4 |
Correct |
8 ms |
5716 KB |
Output is correct |
5 |
Correct |
538 ms |
50312 KB |
Output is correct |
6 |
Correct |
356 ms |
50276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
301 ms |
24764 KB |
Output is correct |
3 |
Correct |
379 ms |
29328 KB |
Output is correct |
4 |
Correct |
113 ms |
17356 KB |
Output is correct |
5 |
Correct |
146 ms |
20668 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
7 ms |
5716 KB |
Output is correct |
11 |
Correct |
7 ms |
5716 KB |
Output is correct |
12 |
Correct |
117 ms |
17416 KB |
Output is correct |
13 |
Correct |
184 ms |
20780 KB |
Output is correct |
14 |
Correct |
122 ms |
17388 KB |
Output is correct |
15 |
Correct |
137 ms |
16732 KB |
Output is correct |
16 |
Correct |
111 ms |
17420 KB |
Output is correct |
17 |
Correct |
131 ms |
19368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5716 KB |
Output is correct |
2 |
Correct |
7 ms |
5716 KB |
Output is correct |
3 |
Incorrect |
35 ms |
10068 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '17480985113680' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Incorrect |
1 ms |
340 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '158784386442' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Incorrect |
1 ms |
340 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '158784386442' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Incorrect |
1 ms |
340 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '158784386442' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
5716 KB |
Output is correct |
2 |
Correct |
7 ms |
5716 KB |
Output is correct |
3 |
Incorrect |
35 ms |
10068 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '17480985113680' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
137 ms |
17192 KB |
Output is correct |
2 |
Correct |
151 ms |
20560 KB |
Output is correct |
3 |
Correct |
7 ms |
5716 KB |
Output is correct |
4 |
Correct |
8 ms |
5716 KB |
Output is correct |
5 |
Correct |
538 ms |
50312 KB |
Output is correct |
6 |
Correct |
356 ms |
50276 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
301 ms |
24764 KB |
Output is correct |
9 |
Correct |
379 ms |
29328 KB |
Output is correct |
10 |
Correct |
113 ms |
17356 KB |
Output is correct |
11 |
Correct |
146 ms |
20668 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
7 ms |
5716 KB |
Output is correct |
17 |
Correct |
7 ms |
5716 KB |
Output is correct |
18 |
Correct |
117 ms |
17416 KB |
Output is correct |
19 |
Correct |
184 ms |
20780 KB |
Output is correct |
20 |
Correct |
122 ms |
17388 KB |
Output is correct |
21 |
Correct |
137 ms |
16732 KB |
Output is correct |
22 |
Correct |
111 ms |
17420 KB |
Output is correct |
23 |
Correct |
131 ms |
19368 KB |
Output is correct |
24 |
Correct |
7 ms |
5716 KB |
Output is correct |
25 |
Correct |
7 ms |
5716 KB |
Output is correct |
26 |
Incorrect |
35 ms |
10068 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '17480985113680' |
27 |
Halted |
0 ms |
0 KB |
- |