#include <bits/stdc++.h>
#include "closing.h"
using namespace std;
#define ll long long
#define sz size()
#define ff first
#define ss second
#define pb push_back
#define pii pair <int, int>
const int N = 2e5 + 5;
ll p[N], vis[N], q[N], jog[N];
int n;
int max_score(int N, int X, int Y, long long K, vector<int> U, vector<int> V, vector<int> W) {
n = N;
// for (int i = 0; i < N - 1; ++i) {
// v[U[i]].pb ({V[i], W[i]});
// v[V[i]].pb ({U[i], W[i]});
// }
// return 1;
ll sum = 0;
for (int i = X + 1; i < N; ++i) {
//
sum += W[i - 1];
p[i] = sum;
}
sum = 0;
for (int i = X - 1; i >= 0; i--) {
sum += W[i];
p[i] = sum;
}
sum = 0;
for (int i = Y + 1; i < N; ++i) {
//
sum += W[i - 1];
q[i] = sum;
}
sum = 0;
for (int i = Y - 1; i >= 0; i--) {
sum += W[i];
q[i] = sum;
}
// exit(0);
for (int i = 0; i < n; ++i) {
jog[i] = max (q[i], p[i]);
}
// for (int i = 0; i < n; ++i) {
// cout << p[i] << " ";
// }
// cout << "\n";
// for (int i = 0; i < n; ++i) {
// cout << q[i] << " ";
// }
// cout << "\n";
// for (int i = 0; i < n; ++i) {
// cout << jog[i] << " ";
// }
// exit(0);
for (int i = 1; i < n; ++i) {
jog[i] += jog[i - 1];
}
int ret = 0;
for (int i = 0; i <= X; ++i) {
for (int j = X; j < n; ++j) {
for (int l = 0; l <= Y; ++l) {
for (int r = Y; r < n; ++r) {
for (int k = 0; k < n; ++k) {
vis[k] = -1;
}
for (int k = i; k <= j; ++k) {
vis[k] = p[k];
}
for (int k = l; k <= r; ++k) {
if (vis[k] == -1) {
vis[k] = q[k];
}
else {
vis[k] = max (vis[k], q[k]);
}
}
ll val = 0;
for (int k = 0; k < n; ++k) {
if (~vis[k]) val += vis[k];
}
if (val <= K) {
ret = max (ret, (X - i + 1) + (j - X) + (Y - l + 1) + (r - Y));
}
}
}
}
}
for (int i = 0; i < n; ++i) {
p[i] = q[i] = jog[i] = 0;
}
return ret;
}
//int main() {
// freopen ("input.txt", "r", stdin);
//
//// cout << max_score(7, 0, 2, 10, [0, 0, 1, 2, 2, 5], [1, 3, 2, 4, 5, 6], [2, 3, 4, 2, 5, 3]);
//
// int Q;
// assert(1 == scanf("%d", &Q));
//
// std::vector<int> N(Q), X(Q), Y(Q);
// std::vector<long long> d, K(Q);
// std::vector<std::vector<int>> U(Q), V(Q), W(Q);
//
// for (int q = 0; q < Q; q++)
// {
// assert(4 == scanf("%d %d %d %lld", &N[q], &X[q], &Y[q], &K[q]));
//
// U[q].resize(N[q] - 1);
// V[q].resize(N[q] - 1);
// W[q].resize(N[q] - 1);
// for (int i = 0; i < N[q] - 1; ++i)
// {
// assert(3 == scanf("%d %d %d", &U[q][i], &V[q][i], &W[q][i]));
// }
// }
// fclose(stdin);
//
// std::vector<int> result(Q);
// for (int q = 0; q < Q; q++)
// {
// result[q] = max_score(N[q], X[q], Y[q], K[q], U[q], V[q], W[q]);
// }
//
// for (int q = 0; q < Q; q++)
// {
// printf("%d\n", result[q]);
// }
// fclose(stdout);
//
// return 0;
//}
/*
2
7 0 2 10
0 1 2
0 3 3
1 2 4
2 4 2
2 5 5
5 6 3
4 0 3 20
0 1 18
1 2 1
2 3 19
answer : 6 3
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4440 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 |
Execution timed out |
1070 ms |
11348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
26 ms |
4440 KB |
Output is correct |
7 |
Correct |
20 ms |
4440 KB |
Output is correct |
8 |
Correct |
7 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
26 ms |
4440 KB |
Output is correct |
7 |
Correct |
20 ms |
4440 KB |
Output is correct |
8 |
Correct |
7 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
92 ms |
4440 KB |
Output is correct |
13 |
Correct |
61 ms |
4444 KB |
Output is correct |
14 |
Correct |
182 ms |
4444 KB |
Output is correct |
15 |
Correct |
79 ms |
4444 KB |
Output is correct |
16 |
Correct |
3 ms |
4440 KB |
Output is correct |
17 |
Correct |
2 ms |
4444 KB |
Output is correct |
18 |
Correct |
7 ms |
4440 KB |
Output is correct |
19 |
Execution timed out |
1098 ms |
4576 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
26 ms |
4440 KB |
Output is correct |
7 |
Correct |
20 ms |
4440 KB |
Output is correct |
8 |
Correct |
7 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
92 ms |
4440 KB |
Output is correct |
13 |
Correct |
61 ms |
4444 KB |
Output is correct |
14 |
Correct |
182 ms |
4444 KB |
Output is correct |
15 |
Correct |
79 ms |
4444 KB |
Output is correct |
16 |
Correct |
3 ms |
4440 KB |
Output is correct |
17 |
Correct |
2 ms |
4444 KB |
Output is correct |
18 |
Correct |
7 ms |
4440 KB |
Output is correct |
19 |
Execution timed out |
1098 ms |
4576 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
4440 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 |
1 ms |
4440 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 |
1 ms |
4440 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 |
1 ms |
4440 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 |
1 ms |
4440 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |