#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
long long max_weights(int n, int m, std::vector<int> x, std::vector<int> y,
std::vector<int> w)
{
n += 2;
vector < map < int, ll > > a (n);
for (int i = 0; i < n; ++i) a[i][n - 3] = 0;
for (int i = 0; i < m; ++i) a[x[i] + 1][y[i]] += w[i];
ll mxdp = 0;
vector < map < int, ll > > p (3), q (2), dp (3);
for (int i = 2; i < n; ++i)
{
set < int > is;
for (int j = 0; j < 3; ++j)
for (auto &x : a[i - j]) is.insert (x.first);
ll ls = 0, rs = 0, ms = 0;
ll mxp = -1e18, mxq = -1e18;
stack < int > st;
auto itp = p[2].begin ();
auto itq = q[1].begin ();
for (auto &x : is)
{
st.push (x);
ls += a[i - 2].count (x) ? a[i - 2][x] : 0ll;
ms += a[i - 1].count (x) ? a[i - 1][x] : 0ll;
rs += a[i].count (x) ? a[i][x] : 0ll;
dp[0][x] = ls + rs + mxdp;
while (itp != p[2].end () && itp->first <= x)
mxp = max (mxp, itp->second), ++itp;
while (itq != q[1].end () && itq->first <= x)
mxq = max (mxq, itq->second), ++itq;
dp[0][x] = max (dp[0][x], ls + rs + mxp);
dp[0][x] = max (dp[0][x], ls + rs + mxq);
}
mxp = -1e18, mxq = -1e18;
auto ritp = dp[2].rbegin (), ritq = dp[1].rbegin ();
while (st.size ())
{
int x = st.top ();
st.pop ();
while (ritp != dp[2].rend () && ritp->first >= x)
mxp = max (mxp, ritp->second), ++ritp;
while (ritq != dp[1].rend () && ritq->first >= x)
mxq = max (mxq, ritq->second), ++ritq;
dp[0][x] = max (dp[0][x], rs + mxp);
dp[0][x] = max (dp[0][x], rs + mxq - ms);
p[0][x] = dp[0][x] - rs;
q[0][x] = dp[0][x] - ms - rs;
ls -= a[i - 2].count (x) ? a[i - 2][x] : 0ll;
ms -= a[i - 1].count (x) ? a[i - 1][x] : 0ll;
rs -= a[i].count (x) ? a[i][x] : 0ll;
}
swap (p[2], p[1]);
swap (p[1], p[0]);
p[0].clear ();
swap (q[1], q[0]);
q[0].clear ();
swap (dp[2], dp[1]);
swap (dp[1], dp[0]);
for (auto &x : dp[0]) mxdp = max (mxdp, x.second);
dp[0].clear ();
}
for (int i = 1; i <= 2; ++i) for (auto &x : dp[i]) mxdp = max (mxdp, x.second);
return mxdp;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
345 ms |
52568 KB |
Output is correct |
2 |
Correct |
556 ms |
64040 KB |
Output is correct |
3 |
Correct |
41 ms |
11356 KB |
Output is correct |
4 |
Correct |
32 ms |
11356 KB |
Output is correct |
5 |
Execution timed out |
1080 ms |
92756 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
778 ms |
73728 KB |
1st lines differ - on the 1st token, expected: '40604614618209', found: '80957127419834' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
11356 KB |
Output is correct |
2 |
Correct |
32 ms |
11356 KB |
Output is correct |
3 |
Correct |
64 ms |
15832 KB |
Output is correct |
4 |
Correct |
61 ms |
14940 KB |
Output is correct |
5 |
Correct |
113 ms |
21604 KB |
Output is correct |
6 |
Correct |
103 ms |
20968 KB |
Output is correct |
7 |
Correct |
157 ms |
21560 KB |
Output is correct |
8 |
Correct |
110 ms |
21432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '254964121270' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '254964121270' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '216624184325', found: '254964121270' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
11356 KB |
Output is correct |
2 |
Correct |
32 ms |
11356 KB |
Output is correct |
3 |
Correct |
64 ms |
15832 KB |
Output is correct |
4 |
Correct |
61 ms |
14940 KB |
Output is correct |
5 |
Correct |
113 ms |
21604 KB |
Output is correct |
6 |
Correct |
103 ms |
20968 KB |
Output is correct |
7 |
Correct |
157 ms |
21560 KB |
Output is correct |
8 |
Correct |
110 ms |
21432 KB |
Output is correct |
9 |
Correct |
180 ms |
21344 KB |
Output is correct |
10 |
Incorrect |
94 ms |
16240 KB |
1st lines differ - on the 1st token, expected: '36454348383152', found: '37838158552678' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
345 ms |
52568 KB |
Output is correct |
2 |
Correct |
556 ms |
64040 KB |
Output is correct |
3 |
Correct |
41 ms |
11356 KB |
Output is correct |
4 |
Correct |
32 ms |
11356 KB |
Output is correct |
5 |
Execution timed out |
1080 ms |
92756 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |