#include "jelly.h"
#include <vector>
#include <algorithm>
#include <map>
const int MAXMONEY = 10005;
class name{
public:
int x;
int y;
bool operator<(const name& other) const{
return x < other.x;
}
};
class node{
public:
int value;
int count;
node* left = nullptr;
node* right = nullptr;
};
int get_mid(int left,int right) {
return (right - left) / 2 + left;
}
int get_value(node* root) {
if(!root) return 0;
return root->value;
}
int get_count(node* root) {
if(!root) return 0;
return root->count;
}
void add(node* root,int pos,int value,int left = 0,int right = MAXMONEY) {
if(right == left) {
root->value = value;
root->count = 1;
return;
}
int mid = get_mid(left,right);
if(pos <= mid) {
if(root->left == nullptr) root->left = new node();
add(root->left,pos,value,left,mid);
}
else {
if(root->right == nullptr) root->right = new node();
add(root->right,pos,value,mid + 1,right);
}
root->value = get_value(root->left) + get_value(root->right);
root->count = get_count(root->left) + get_count(root->right);
}
int get_max_count(node* root,int max_value,int left = 0,int right = MAXMONEY) {
if(!root) return 0;
int mid = get_mid(left,right);
if(max_value >= get_value(root->left)) {
return get_count(root->left) + get_max_count(root->right,max_value - get_value(root->left),mid + 1,right);
}
else {
return get_max_count(root->left,max_value,left,mid);
}
}
int find_maximum_unique(int x, int y, std::vector<int> a, std::vector<int> b) {
int N = a.size();
int ans = 0;
std::vector<name> v(N);
for(int q = 0;q < N;q++) {
v[q].x = a[q];
v[q].y = b[q];
}
std::sort(v.begin(),v.end());
std::vector<int> dp(MAXMONEY,20000);
dp[0] = 0;
std::vector<int> res(N,20000);
int min_require = 0;
for(int q = 0;q < N;q++) {
min_require += v[q].x;
for(int w = MAXMONEY - 1;w>=0;w--) {
if(w < v[q].x) break;
dp[w] = std::min(dp[w],dp[w - v[q].x] + v[q].y);
}
for(int w = std::max(0,min_require - x);w < MAXMONEY;w++) {
if(dp[w] <= y) {
res[q] = std::min(res[q],dp[w]);
}
}
}
if(res.back() <= y) return N;
std::vector<name> u(N);
for(int q = 0;q < N;q++) {
u[q].x = v[q].y;
u[q].y = q;
}
std::sort(u.begin(),u.end());
std::map<int,int> mm;
for(int q = 0;q < N;q++) {
mm[u[q].y] = q;
}
node* root = new node();
for(int q = N - 1;q>=1;q--) {
add(root,mm[q],v[q].y);
if(res[q - 1] <= y) {
int remain_value = y - res[q];
ans = std::max(ans,q + get_max_count(root,remain_value));
}
}
add(root,mm[0],v[0].y);
ans = std::max(ans,get_max_count(root,y));
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '8', found: '7' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '8', found: '7' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
20 ms |
604 KB |
1st lines differ - on the 1st token, expected: '689', found: '688' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
604 KB |
Output is correct |
2 |
Correct |
12 ms |
512 KB |
Output is correct |
3 |
Correct |
12 ms |
604 KB |
Output is correct |
4 |
Correct |
47 ms |
592 KB |
Output is correct |
5 |
Correct |
49 ms |
348 KB |
Output is correct |
6 |
Correct |
16 ms |
600 KB |
Output is correct |
7 |
Correct |
12 ms |
512 KB |
Output is correct |
8 |
Correct |
11 ms |
508 KB |
Output is correct |
9 |
Correct |
50 ms |
600 KB |
Output is correct |
10 |
Correct |
50 ms |
348 KB |
Output is correct |
11 |
Correct |
21 ms |
604 KB |
Output is correct |
12 |
Correct |
32 ms |
504 KB |
Output is correct |
13 |
Correct |
22 ms |
512 KB |
Output is correct |
14 |
Correct |
31 ms |
408 KB |
Output is correct |
15 |
Correct |
32 ms |
500 KB |
Output is correct |
16 |
Correct |
28 ms |
596 KB |
Output is correct |
17 |
Correct |
12 ms |
604 KB |
Output is correct |
18 |
Correct |
12 ms |
512 KB |
Output is correct |
19 |
Correct |
37 ms |
604 KB |
Output is correct |
20 |
Correct |
33 ms |
504 KB |
Output is correct |
21 |
Correct |
12 ms |
604 KB |
Output is correct |
22 |
Correct |
12 ms |
604 KB |
Output is correct |
23 |
Correct |
16 ms |
512 KB |
Output is correct |
24 |
Correct |
46 ms |
504 KB |
Output is correct |
25 |
Correct |
48 ms |
348 KB |
Output is correct |
26 |
Correct |
12 ms |
600 KB |
Output is correct |
27 |
Correct |
17 ms |
604 KB |
Output is correct |
28 |
Correct |
11 ms |
512 KB |
Output is correct |
29 |
Correct |
45 ms |
348 KB |
Output is correct |
30 |
Correct |
54 ms |
348 KB |
Output is correct |
31 |
Correct |
21 ms |
592 KB |
Output is correct |
32 |
Correct |
31 ms |
500 KB |
Output is correct |
33 |
Correct |
23 ms |
604 KB |
Output is correct |
34 |
Correct |
31 ms |
348 KB |
Output is correct |
35 |
Correct |
33 ms |
596 KB |
Output is correct |
36 |
Correct |
30 ms |
596 KB |
Output is correct |
37 |
Correct |
15 ms |
600 KB |
Output is correct |
38 |
Correct |
12 ms |
600 KB |
Output is correct |
39 |
Correct |
38 ms |
500 KB |
Output is correct |
40 |
Correct |
33 ms |
504 KB |
Output is correct |
41 |
Correct |
12 ms |
600 KB |
Output is correct |
42 |
Correct |
12 ms |
604 KB |
Output is correct |
43 |
Correct |
12 ms |
512 KB |
Output is correct |
44 |
Correct |
46 ms |
596 KB |
Output is correct |
45 |
Correct |
49 ms |
344 KB |
Output is correct |
46 |
Correct |
11 ms |
600 KB |
Output is correct |
47 |
Correct |
12 ms |
604 KB |
Output is correct |
48 |
Correct |
11 ms |
508 KB |
Output is correct |
49 |
Correct |
45 ms |
492 KB |
Output is correct |
50 |
Correct |
47 ms |
348 KB |
Output is correct |
51 |
Correct |
21 ms |
592 KB |
Output is correct |
52 |
Correct |
39 ms |
504 KB |
Output is correct |
53 |
Correct |
23 ms |
600 KB |
Output is correct |
54 |
Correct |
31 ms |
348 KB |
Output is correct |
55 |
Correct |
37 ms |
592 KB |
Output is correct |
56 |
Correct |
23 ms |
600 KB |
Output is correct |
57 |
Correct |
13 ms |
512 KB |
Output is correct |
58 |
Correct |
12 ms |
508 KB |
Output is correct |
59 |
Correct |
37 ms |
504 KB |
Output is correct |
60 |
Correct |
33 ms |
596 KB |
Output is correct |
61 |
Correct |
12 ms |
604 KB |
Output is correct |
62 |
Correct |
13 ms |
600 KB |
Output is correct |
63 |
Correct |
12 ms |
604 KB |
Output is correct |
64 |
Correct |
47 ms |
508 KB |
Output is correct |
65 |
Correct |
48 ms |
348 KB |
Output is correct |
66 |
Correct |
11 ms |
604 KB |
Output is correct |
67 |
Correct |
12 ms |
600 KB |
Output is correct |
68 |
Correct |
11 ms |
604 KB |
Output is correct |
69 |
Correct |
53 ms |
488 KB |
Output is correct |
70 |
Correct |
47 ms |
484 KB |
Output is correct |
71 |
Correct |
21 ms |
604 KB |
Output is correct |
72 |
Correct |
31 ms |
504 KB |
Output is correct |
73 |
Correct |
22 ms |
484 KB |
Output is correct |
74 |
Correct |
31 ms |
348 KB |
Output is correct |
75 |
Correct |
32 ms |
596 KB |
Output is correct |
76 |
Correct |
23 ms |
504 KB |
Output is correct |
77 |
Correct |
13 ms |
604 KB |
Output is correct |
78 |
Correct |
12 ms |
600 KB |
Output is correct |
79 |
Correct |
36 ms |
592 KB |
Output is correct |
80 |
Correct |
33 ms |
596 KB |
Output is correct |
81 |
Correct |
12 ms |
604 KB |
Output is correct |
82 |
Correct |
12 ms |
604 KB |
Output is correct |
83 |
Correct |
12 ms |
604 KB |
Output is correct |
84 |
Correct |
51 ms |
508 KB |
Output is correct |
85 |
Correct |
48 ms |
348 KB |
Output is correct |
86 |
Correct |
11 ms |
604 KB |
Output is correct |
87 |
Correct |
14 ms |
604 KB |
Output is correct |
88 |
Correct |
11 ms |
600 KB |
Output is correct |
89 |
Correct |
45 ms |
348 KB |
Output is correct |
90 |
Correct |
48 ms |
348 KB |
Output is correct |
91 |
Correct |
21 ms |
600 KB |
Output is correct |
92 |
Correct |
31 ms |
596 KB |
Output is correct |
93 |
Correct |
22 ms |
604 KB |
Output is correct |
94 |
Correct |
31 ms |
512 KB |
Output is correct |
95 |
Correct |
32 ms |
600 KB |
Output is correct |
96 |
Correct |
23 ms |
484 KB |
Output is correct |
97 |
Correct |
13 ms |
600 KB |
Output is correct |
98 |
Correct |
14 ms |
600 KB |
Output is correct |
99 |
Correct |
37 ms |
592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
600 KB |
Output is correct |
2 |
Correct |
12 ms |
600 KB |
Output is correct |
3 |
Correct |
13 ms |
512 KB |
Output is correct |
4 |
Correct |
47 ms |
348 KB |
Output is correct |
5 |
Correct |
53 ms |
596 KB |
Output is correct |
6 |
Correct |
12 ms |
604 KB |
Output is correct |
7 |
Correct |
12 ms |
600 KB |
Output is correct |
8 |
Correct |
12 ms |
604 KB |
Output is correct |
9 |
Correct |
47 ms |
492 KB |
Output is correct |
10 |
Correct |
48 ms |
344 KB |
Output is correct |
11 |
Correct |
20 ms |
508 KB |
Output is correct |
12 |
Correct |
32 ms |
592 KB |
Output is correct |
13 |
Correct |
19 ms |
508 KB |
Output is correct |
14 |
Correct |
31 ms |
512 KB |
Output is correct |
15 |
Correct |
39 ms |
596 KB |
Output is correct |
16 |
Correct |
19 ms |
604 KB |
Output is correct |
17 |
Correct |
25 ms |
604 KB |
Output is correct |
18 |
Correct |
19 ms |
604 KB |
Output is correct |
19 |
Correct |
33 ms |
516 KB |
Output is correct |
20 |
Correct |
34 ms |
592 KB |
Output is correct |
21 |
Correct |
21 ms |
596 KB |
Output is correct |
22 |
Correct |
13 ms |
604 KB |
Output is correct |
23 |
Correct |
12 ms |
604 KB |
Output is correct |
24 |
Correct |
53 ms |
592 KB |
Output is correct |
25 |
Correct |
45 ms |
504 KB |
Output is correct |
26 |
Correct |
12 ms |
600 KB |
Output is correct |
27 |
Correct |
13 ms |
516 KB |
Output is correct |
28 |
Correct |
12 ms |
604 KB |
Output is correct |
29 |
Correct |
47 ms |
348 KB |
Output is correct |
30 |
Correct |
48 ms |
492 KB |
Output is correct |
31 |
Correct |
21 ms |
600 KB |
Output is correct |
32 |
Correct |
32 ms |
600 KB |
Output is correct |
33 |
Correct |
19 ms |
604 KB |
Output is correct |
34 |
Correct |
36 ms |
500 KB |
Output is correct |
35 |
Correct |
35 ms |
488 KB |
Output is correct |
36 |
Correct |
19 ms |
600 KB |
Output is correct |
37 |
Correct |
24 ms |
600 KB |
Output is correct |
38 |
Correct |
19 ms |
604 KB |
Output is correct |
39 |
Correct |
34 ms |
596 KB |
Output is correct |
40 |
Correct |
40 ms |
512 KB |
Output is correct |
41 |
Correct |
20 ms |
604 KB |
Output is correct |
42 |
Correct |
12 ms |
604 KB |
Output is correct |
43 |
Correct |
13 ms |
720 KB |
Output is correct |
44 |
Correct |
47 ms |
348 KB |
Output is correct |
45 |
Correct |
45 ms |
592 KB |
Output is correct |
46 |
Correct |
13 ms |
600 KB |
Output is correct |
47 |
Correct |
13 ms |
600 KB |
Output is correct |
48 |
Correct |
12 ms |
512 KB |
Output is correct |
49 |
Correct |
49 ms |
348 KB |
Output is correct |
50 |
Correct |
52 ms |
344 KB |
Output is correct |
51 |
Correct |
27 ms |
604 KB |
Output is correct |
52 |
Correct |
45 ms |
596 KB |
Output is correct |
53 |
Correct |
18 ms |
604 KB |
Output is correct |
54 |
Correct |
32 ms |
500 KB |
Output is correct |
55 |
Correct |
35 ms |
344 KB |
Output is correct |
56 |
Correct |
19 ms |
604 KB |
Output is correct |
57 |
Correct |
21 ms |
512 KB |
Output is correct |
58 |
Correct |
19 ms |
600 KB |
Output is correct |
59 |
Correct |
34 ms |
596 KB |
Output is correct |
60 |
Correct |
34 ms |
592 KB |
Output is correct |
61 |
Correct |
22 ms |
592 KB |
Output is correct |
62 |
Correct |
13 ms |
604 KB |
Output is correct |
63 |
Correct |
13 ms |
600 KB |
Output is correct |
64 |
Correct |
47 ms |
348 KB |
Output is correct |
65 |
Correct |
45 ms |
596 KB |
Output is correct |
66 |
Correct |
12 ms |
600 KB |
Output is correct |
67 |
Correct |
13 ms |
600 KB |
Output is correct |
68 |
Correct |
12 ms |
604 KB |
Output is correct |
69 |
Correct |
47 ms |
344 KB |
Output is correct |
70 |
Correct |
52 ms |
344 KB |
Output is correct |
71 |
Correct |
21 ms |
604 KB |
Output is correct |
72 |
Correct |
35 ms |
504 KB |
Output is correct |
73 |
Correct |
18 ms |
504 KB |
Output is correct |
74 |
Correct |
32 ms |
508 KB |
Output is correct |
75 |
Correct |
45 ms |
348 KB |
Output is correct |
76 |
Correct |
19 ms |
600 KB |
Output is correct |
77 |
Correct |
20 ms |
604 KB |
Output is correct |
78 |
Correct |
21 ms |
512 KB |
Output is correct |
79 |
Correct |
34 ms |
504 KB |
Output is correct |
80 |
Correct |
34 ms |
600 KB |
Output is correct |
81 |
Correct |
21 ms |
600 KB |
Output is correct |
82 |
Correct |
12 ms |
604 KB |
Output is correct |
83 |
Correct |
18 ms |
508 KB |
Output is correct |
84 |
Correct |
47 ms |
344 KB |
Output is correct |
85 |
Correct |
45 ms |
600 KB |
Output is correct |
86 |
Correct |
13 ms |
604 KB |
Output is correct |
87 |
Correct |
13 ms |
508 KB |
Output is correct |
88 |
Correct |
13 ms |
604 KB |
Output is correct |
89 |
Correct |
47 ms |
488 KB |
Output is correct |
90 |
Correct |
49 ms |
348 KB |
Output is correct |
91 |
Correct |
20 ms |
600 KB |
Output is correct |
92 |
Correct |
41 ms |
484 KB |
Output is correct |
93 |
Correct |
19 ms |
604 KB |
Output is correct |
94 |
Correct |
32 ms |
504 KB |
Output is correct |
95 |
Correct |
35 ms |
344 KB |
Output is correct |
96 |
Correct |
19 ms |
604 KB |
Output is correct |
97 |
Correct |
19 ms |
604 KB |
Output is correct |
98 |
Correct |
19 ms |
604 KB |
Output is correct |
99 |
Correct |
34 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
1st lines differ - on the 1st token, expected: '8', found: '7' |
2 |
Halted |
0 ms |
0 KB |
- |