#include <bits/stdc++.h>
#include "fish.h"
using namespace std;
using ll = long long;
struct A {
int v, w;
ll ans;
bool operator < (const A& o) const {
return v < o.v;
}
};
vector<A> pos[100100];
int n, m;
ll 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] + 1].push_back({ Y[i] + 1, W[i], 0ll });
}
pos[1].push_back({ 0, 0, 0ll });
pos[1].push_back({ N + 1, 0, 0ll });
sort(pos[1].begin(), pos[1].end());
ll ans = 0;
for (int i = 2;i <= N;i++) {
pos[i].push_back({ 0, 0, 0 });
pos[i].push_back({ N + 1, 0, 0ll });
sort(pos[i].begin(), pos[i].end());
int n = pos[i - 1].size(), m = pos[i].size();
// a[i-1] <= a[i]
ll sum = 0;
ll mx = 0;
for (int j = 0, p = 0;j < m;j++) {
while (p < n && pos[i - 1][p].v <= pos[i][j].v) {
sum += pos[i - 1][p].w;
mx = max(mx, pos[i - 1][p].ans - sum);
p++;
}
pos[i][j].ans = max(pos[i][j].ans, sum + mx);
ans = max(ans, pos[i][j].ans);
}
// a[i-1] > a[i]
sum = 0;
mx = 0;
for (int j = m - 1, p = n - 1;j >= 0;j--) {
while (p >= 0 && pos[i - 1][p].v > pos[i][j].v) {
mx = max(mx, pos[i - 1][p].ans - sum);
p--;
}
pos[i][j].ans = max(pos[i][j].ans, sum + mx);
ans = max(ans, pos[i][j].ans);
sum += pos[i][j].w;
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
10176 KB |
Output is correct |
2 |
Correct |
40 ms |
11200 KB |
Output is correct |
3 |
Correct |
10 ms |
7488 KB |
Output is correct |
4 |
Correct |
10 ms |
7256 KB |
Output is correct |
5 |
Incorrect |
112 ms |
19200 KB |
1st lines differ - on the 1st token, expected: '149814460735479', found: '299628921470958' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Incorrect |
61 ms |
13368 KB |
1st lines differ - on the 1st token, expected: '40604614618209', found: '80958394776886' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
7260 KB |
Output is correct |
2 |
Correct |
10 ms |
7260 KB |
Output is correct |
3 |
Incorrect |
26 ms |
10348 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '32717839057000' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2788 KB |
Output is correct |
5 |
Correct |
1 ms |
2792 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2904 KB |
Output is correct |
9 |
Incorrect |
1 ms |
2800 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '326244703878' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2788 KB |
Output is correct |
5 |
Correct |
1 ms |
2792 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2904 KB |
Output is correct |
9 |
Incorrect |
1 ms |
2800 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '326244703878' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2788 KB |
Output is correct |
5 |
Correct |
1 ms |
2792 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2904 KB |
Output is correct |
9 |
Incorrect |
1 ms |
2800 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '326244703878' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
7260 KB |
Output is correct |
2 |
Correct |
10 ms |
7260 KB |
Output is correct |
3 |
Incorrect |
26 ms |
10348 KB |
1st lines differ - on the 1st token, expected: '21261825233649', found: '32717839057000' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
10176 KB |
Output is correct |
2 |
Correct |
40 ms |
11200 KB |
Output is correct |
3 |
Correct |
10 ms |
7488 KB |
Output is correct |
4 |
Correct |
10 ms |
7256 KB |
Output is correct |
5 |
Incorrect |
112 ms |
19200 KB |
1st lines differ - on the 1st token, expected: '149814460735479', found: '299628921470958' |
6 |
Halted |
0 ms |
0 KB |
- |