#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];
int out(int a, int b, int remain) {
vector<int> outside;
int ret = 0;
for (int i = x; i >= 0; i--) outside.push_back(max(0LL, dsum[x] - dsum[i] - need[i]));
for (int i = y; i < n; i++) outside.push_back(max(0LL, dsum[i] - dsum[y] - need[i]));
sort(outside.begin(), outside.end());
for (int i = 0; i < outside.size(); i++) {
if (remain >= outside[i]) {
ret++;
remain -= outside[i];
}
else break;
}
return ret;
}
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];
for (int a = 0; a < n - x; a++) {
ll sum = 0;
for (int i = 0; i < n; i++) need[i] = 0;
for (int i = x + 1; i <= a + x; i++) need[i] = dsum[i] - dsum[x];
for (int i = x + 1; i <= a + x; i++) sum += need[i];
for (int b = 0; b <= y; b++) {
if (need[y - b] < dsum[y] - dsum[y - b]) {
sum += dsum[y] - dsum[y - b] - need[y - b];
need[y - b] = dsum[y] - dsum[y - b];
}
if (sum <= k) ans = max(ans, a + b + out(a, b, k - sum));
else break;
//cout << a << " " << b << "\n";
}
}
return ans;
}
Compilation message
closing.cpp: In function 'int out(int, int, int)':
closing.cpp:17:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for (int i = 0; i < outside.size(); i++) {
| ~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
8792 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 |
1065 ms |
26720 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8792 KB |
Output is correct |
2 |
Correct |
1 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8792 KB |
Output is correct |
4 |
Correct |
1 ms |
8792 KB |
Output is correct |
5 |
Correct |
1 ms |
8792 KB |
Output is correct |
6 |
Correct |
2 ms |
8792 KB |
Output is correct |
7 |
Correct |
2 ms |
8792 KB |
Output is correct |
8 |
Correct |
2 ms |
8792 KB |
Output is correct |
9 |
Correct |
1 ms |
8792 KB |
Output is correct |
10 |
Correct |
2 ms |
8792 KB |
Output is correct |
11 |
Correct |
2 ms |
8796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8792 KB |
Output is correct |
2 |
Correct |
1 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8792 KB |
Output is correct |
4 |
Correct |
1 ms |
8792 KB |
Output is correct |
5 |
Correct |
1 ms |
8792 KB |
Output is correct |
6 |
Correct |
2 ms |
8792 KB |
Output is correct |
7 |
Correct |
2 ms |
8792 KB |
Output is correct |
8 |
Correct |
2 ms |
8792 KB |
Output is correct |
9 |
Correct |
1 ms |
8792 KB |
Output is correct |
10 |
Correct |
2 ms |
8792 KB |
Output is correct |
11 |
Correct |
2 ms |
8796 KB |
Output is correct |
12 |
Correct |
2 ms |
8792 KB |
Output is correct |
13 |
Correct |
2 ms |
8792 KB |
Output is correct |
14 |
Correct |
4 ms |
8952 KB |
Output is correct |
15 |
Correct |
2 ms |
8792 KB |
Output is correct |
16 |
Correct |
2 ms |
8792 KB |
Output is correct |
17 |
Correct |
2 ms |
8796 KB |
Output is correct |
18 |
Correct |
2 ms |
8796 KB |
Output is correct |
19 |
Correct |
238 ms |
8832 KB |
Output is correct |
20 |
Correct |
2 ms |
8792 KB |
Output is correct |
21 |
Correct |
291 ms |
8792 KB |
Output is correct |
22 |
Correct |
2 ms |
8792 KB |
Output is correct |
23 |
Correct |
5 ms |
8792 KB |
Output is correct |
24 |
Correct |
5 ms |
8792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
8792 KB |
Output is correct |
2 |
Correct |
1 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8792 KB |
Output is correct |
4 |
Correct |
1 ms |
8792 KB |
Output is correct |
5 |
Correct |
1 ms |
8792 KB |
Output is correct |
6 |
Correct |
2 ms |
8792 KB |
Output is correct |
7 |
Correct |
2 ms |
8792 KB |
Output is correct |
8 |
Correct |
2 ms |
8792 KB |
Output is correct |
9 |
Correct |
1 ms |
8792 KB |
Output is correct |
10 |
Correct |
2 ms |
8792 KB |
Output is correct |
11 |
Correct |
2 ms |
8796 KB |
Output is correct |
12 |
Correct |
2 ms |
8792 KB |
Output is correct |
13 |
Correct |
2 ms |
8792 KB |
Output is correct |
14 |
Correct |
4 ms |
8952 KB |
Output is correct |
15 |
Correct |
2 ms |
8792 KB |
Output is correct |
16 |
Correct |
2 ms |
8792 KB |
Output is correct |
17 |
Correct |
2 ms |
8796 KB |
Output is correct |
18 |
Correct |
2 ms |
8796 KB |
Output is correct |
19 |
Correct |
238 ms |
8832 KB |
Output is correct |
20 |
Correct |
2 ms |
8792 KB |
Output is correct |
21 |
Correct |
291 ms |
8792 KB |
Output is correct |
22 |
Correct |
2 ms |
8792 KB |
Output is correct |
23 |
Correct |
5 ms |
8792 KB |
Output is correct |
24 |
Correct |
5 ms |
8792 KB |
Output is correct |
25 |
Correct |
19 ms |
8792 KB |
Output is correct |
26 |
Execution timed out |
1050 ms |
9048 KB |
Time limit exceeded |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
8792 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 |
8792 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 |
8792 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 |
8792 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 |
8792 KB |
1st lines differ - on the 1st token, expected: '6', found: '5' |
2 |
Halted |
0 ms |
0 KB |
- |