#include "closing.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
int n, x, y, ch[202020], ans;
ll k, need[202020], d[202020], dsum[202020];
vector<pll> adj[202020];
pair<int, ll> in[3030][3030];
void inner() {
for (int r = x; r <= y; r++) {
in[r][y].first = r - x + 2;
in[r][y].second = 0;
ll need[3030];
for (int i = x; i <= r; i++) need[i] = dsum[i] - dsum[x];
for (int i = r + 1; i <= y; i++) need[i] = 0;
for (int i = x; i <= y; i++) in[r][y].second += need[i];
for (int l = y - 1; l >= x; l--) {
in[r][l].first = in[r][l + 1].first + 1;
in[r][l].second = in[r][l + 1].second + max(0LL, dsum[y] - dsum[l] - need[l]);
}
}
}
ll dp[404040], nxt[404040];
void update(ll a, ll b) {
for (int i = 0; i <= 2*n; i++) {
ll val = dp[i];
if (i >= 1) val = min(val, dp[i - 1] + a);
if (i >= 2) val = min(val, dp[i - 2] + b);
nxt[i] = val;
}
for (int i = 0; i <= 2*n; i++) dp[i] = nxt[i];
}
void outer() {
for (int i = 0; i <= 2*n; i++) dp[i] = 2e18;
dp[0] = 0;
for (int i = 0; i < x; i++) {
update(dsum[x] - dsum[i], dsum[y] - dsum[i]);
}
for (int i = y + 1; i < n; i++) {
update(dsum[i] - dsum[y], dsum[i] - dsum[x]);
}
}
int max_score(int N, int X, int Y, ll K, vector<int> U, vector<int> V, vector<int> W) {
n = N, x = X, y = Y, k = K;
ans = 0;
for (int i = 0; i < n; i++) adj[i].clear();
for (int i = 0; i < (int)U.size(); i++) {
adj[U[i]].push_back({V[i], W[i]});
adj[V[i]].push_back({U[i], W[i]});
d[max(U[i], V[i])] = W[i];
}
for (int i = 1; i < n; i++) dsum[i] = dsum[i - 1] + d[i];
inner();
outer();
for (int r = x; r <= y; r++) {
for (int l = y; l >= x; l--) {
if (k - in[r][l].second < 0) continue;
int val = in[r][l].first;
int idx = upper_bound(dp, dp + 2*n + 1, k - in[r][l].second) - dp - 1;
ans = max(ans, val + idx);
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
16728 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
83 ms |
54104 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
16732 KB |
Output is correct |
2 |
Correct |
2 ms |
14684 KB |
Output is correct |
3 |
Correct |
3 ms |
14800 KB |
Output is correct |
4 |
Correct |
2 ms |
16732 KB |
Output is correct |
5 |
Correct |
3 ms |
14796 KB |
Output is correct |
6 |
Correct |
3 ms |
14684 KB |
Output is correct |
7 |
Correct |
3 ms |
14684 KB |
Output is correct |
8 |
Correct |
2 ms |
14684 KB |
Output is correct |
9 |
Correct |
2 ms |
16732 KB |
Output is correct |
10 |
Correct |
3 ms |
18776 KB |
Output is correct |
11 |
Correct |
4 ms |
18884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
16732 KB |
Output is correct |
2 |
Correct |
2 ms |
14684 KB |
Output is correct |
3 |
Correct |
3 ms |
14800 KB |
Output is correct |
4 |
Correct |
2 ms |
16732 KB |
Output is correct |
5 |
Correct |
3 ms |
14796 KB |
Output is correct |
6 |
Correct |
3 ms |
14684 KB |
Output is correct |
7 |
Correct |
3 ms |
14684 KB |
Output is correct |
8 |
Correct |
2 ms |
14684 KB |
Output is correct |
9 |
Correct |
2 ms |
16732 KB |
Output is correct |
10 |
Correct |
3 ms |
18776 KB |
Output is correct |
11 |
Correct |
4 ms |
18884 KB |
Output is correct |
12 |
Correct |
2 ms |
14684 KB |
Output is correct |
13 |
Correct |
2 ms |
14684 KB |
Output is correct |
14 |
Correct |
3 ms |
16732 KB |
Output is correct |
15 |
Correct |
3 ms |
14684 KB |
Output is correct |
16 |
Correct |
3 ms |
20828 KB |
Output is correct |
17 |
Correct |
3 ms |
20828 KB |
Output is correct |
18 |
Correct |
3 ms |
16732 KB |
Output is correct |
19 |
Correct |
3 ms |
14684 KB |
Output is correct |
20 |
Correct |
4 ms |
14940 KB |
Output is correct |
21 |
Correct |
6 ms |
29016 KB |
Output is correct |
22 |
Correct |
4 ms |
25136 KB |
Output is correct |
23 |
Correct |
8 ms |
39260 KB |
Output is correct |
24 |
Correct |
7 ms |
39260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
16732 KB |
Output is correct |
2 |
Correct |
2 ms |
14684 KB |
Output is correct |
3 |
Correct |
3 ms |
14800 KB |
Output is correct |
4 |
Correct |
2 ms |
16732 KB |
Output is correct |
5 |
Correct |
3 ms |
14796 KB |
Output is correct |
6 |
Correct |
3 ms |
14684 KB |
Output is correct |
7 |
Correct |
3 ms |
14684 KB |
Output is correct |
8 |
Correct |
2 ms |
14684 KB |
Output is correct |
9 |
Correct |
2 ms |
16732 KB |
Output is correct |
10 |
Correct |
3 ms |
18776 KB |
Output is correct |
11 |
Correct |
4 ms |
18884 KB |
Output is correct |
12 |
Correct |
2 ms |
14684 KB |
Output is correct |
13 |
Correct |
2 ms |
14684 KB |
Output is correct |
14 |
Correct |
3 ms |
16732 KB |
Output is correct |
15 |
Correct |
3 ms |
14684 KB |
Output is correct |
16 |
Correct |
3 ms |
20828 KB |
Output is correct |
17 |
Correct |
3 ms |
20828 KB |
Output is correct |
18 |
Correct |
3 ms |
16732 KB |
Output is correct |
19 |
Correct |
3 ms |
14684 KB |
Output is correct |
20 |
Correct |
4 ms |
14940 KB |
Output is correct |
21 |
Correct |
6 ms |
29016 KB |
Output is correct |
22 |
Correct |
4 ms |
25136 KB |
Output is correct |
23 |
Correct |
8 ms |
39260 KB |
Output is correct |
24 |
Correct |
7 ms |
39260 KB |
Output is correct |
25 |
Correct |
4 ms |
18780 KB |
Output is correct |
26 |
Correct |
29 ms |
14940 KB |
Output is correct |
27 |
Correct |
25 ms |
14940 KB |
Output is correct |
28 |
Correct |
131 ms |
146412 KB |
Output is correct |
29 |
Correct |
78 ms |
103324 KB |
Output is correct |
30 |
Correct |
25 ms |
37672 KB |
Output is correct |
31 |
Correct |
82 ms |
158544 KB |
Output is correct |
32 |
Correct |
82 ms |
158684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
16728 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
16728 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
16728 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
16728 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
16728 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |