#include "jelly.h"
#include <bits/stdc++.h>
using namespace std;
int find_maximum_unique(int x, int y, std::vector<int> a, std::vector<int> b) {
int n = (int) a.size();
vector<pair<int, int>> jellies(n);
for (int i = 0; i < n; i++) {
jellies[i].first = a[i];
jellies[i].second = b[i];
}
sort(jellies.begin(), jellies.end());
vector<int> pref(n), suff(n);
for (int i = 0; i < n; i++) {
vector<int> v;
for (int j = 0; j <= i; j++) {
v.push_back(jellies[j].second);
}
sort(v.begin(), v.end());
int tmp = y;
int cnt = 0;
for (int& cost : v) {
if (tmp - cost >= 0) {
++cnt;
tmp -= cost;
}
}
pref[i] = cnt;
}
for (int i = n - 1; i >= 0; i--) {
vector<int> v;
for (int j = i; j < n; j++) {
v.push_back(jellies[j].second);
}
sort(v.begin(), v.end());
int tmp = y;
int cnt = 0;
for (int& cost : v) {
if (tmp - cost >= 0) {
++cnt;
tmp -= cost;
}
}
suff[i] = cnt;
}
int res = 0;
for (int i = 0; i < n; i++) {
int sum = 0;
for (int j = i; j < n; j++) {
if (sum + jellies[j].first > x) {
break;
}
sum += jellies[j].first;
res = max(res, (j - i + 1) + (i > 0 ? pref[i - 1] : 0) + (j + 1 < n ? suff[j + 1] : 0));
}
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
292 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
292 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Incorrect |
1 ms |
204 KB |
1st lines differ - on the 1st token, expected: '8', found: '7' |
26 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
292 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
292 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Incorrect |
1 ms |
204 KB |
1st lines differ - on the 1st token, expected: '8', found: '7' |
26 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
77 ms |
356 KB |
1st lines differ - on the 1st token, expected: '689', found: '683' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
332 KB |
Output is correct |
2 |
Correct |
52 ms |
340 KB |
Output is correct |
3 |
Correct |
50 ms |
332 KB |
Output is correct |
4 |
Correct |
47 ms |
340 KB |
Output is correct |
5 |
Correct |
50 ms |
340 KB |
Output is correct |
6 |
Correct |
48 ms |
344 KB |
Output is correct |
7 |
Correct |
48 ms |
352 KB |
Output is correct |
8 |
Correct |
48 ms |
332 KB |
Output is correct |
9 |
Correct |
47 ms |
332 KB |
Output is correct |
10 |
Correct |
51 ms |
452 KB |
Output is correct |
11 |
Correct |
48 ms |
344 KB |
Output is correct |
12 |
Correct |
45 ms |
352 KB |
Output is correct |
13 |
Incorrect |
51 ms |
348 KB |
1st lines differ - on the 1st token, expected: '53', found: '54' |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
62 ms |
344 KB |
1st lines differ - on the 1st token, expected: '154', found: '161' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
292 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
292 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Incorrect |
1 ms |
204 KB |
1st lines differ - on the 1st token, expected: '8', found: '7' |
26 |
Halted |
0 ms |
0 KB |
- |