#include <iostream>
#include <set>
#include <algorithm>
#define int long long
using namespace std;
const int nmax = 3e5 + 7;
int v[nmax], b[nmax], cnt[nmax], n, k;
struct pairing {
int first, second;
const bool operator < (pairing a) const {
if(first != a.first) {
return first < a.first;
} else {
return second > a.second;
}
}
};
bool check(int x) {
int sum = x;
for(int i = 2; i <= n; i ++) {
int curr = (v[1] * x) / v[i];
if(v[i] * curr < v[1] * x) {
curr ++;
}
sum += curr;
}
if(sum <= n * k) {
return 1;
}
return 0;
}
int32_t main() {
cin >> n >> k;
for(int i = 1; i <= n; i ++) {
cin >> v[i];
}
for(int i = 1; i <= n; i ++){
cin >> b[i];
}
if(n * k > 3e5) {
sort(v + 1, v + n + 1);
int l = 0, r = n * k;
while(l < r) {
int mid = (l + r) / 2;
if(check(mid) == 1) {
l = mid + 1;
} else {
r = mid;
}
}
while(check(r) == 0) {
r --;
}
while(check(r + 1) == 1) {
r ++;
}
cout << r;
return 0;
}
set<pairing> pq;
for(int i = 1; i <= n; i ++) {
pq.insert({max(v[i], b[i]), i});
cnt[i] = 1;
}
for(int i = 2; i <= k; i ++) {
for(int j = 1; j <= n; j ++) {
pairing curr = *(pq.begin());
int sum = curr.first, ind = curr.second;
pq.erase({sum, ind});
if(cnt[ind] < k) {
sum += max(v[ind], b[ind]);
cnt[ind] ++;
} else {
sum += b[ind];
}
pq.insert({sum, ind});
}
}
int minn = 1e18;
for(auto it : pq) {
// cout << it.first << " " << it.second << endl;
minn = min(minn, it.first);
}
cout << minn;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
596 KB |
Output is correct |
11 |
Correct |
316 ms |
26004 KB |
Output is correct |
12 |
Correct |
308 ms |
26084 KB |
Output is correct |
13 |
Correct |
183 ms |
26084 KB |
Output is correct |
14 |
Correct |
185 ms |
26116 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
130 ms |
27212 KB |
Output is correct |
17 |
Correct |
258 ms |
32644 KB |
Output is correct |
18 |
Correct |
303 ms |
31820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
130 ms |
27212 KB |
Output is correct |
3 |
Correct |
258 ms |
32644 KB |
Output is correct |
4 |
Correct |
303 ms |
31820 KB |
Output is correct |
5 |
Correct |
1 ms |
216 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
164 ms |
16016 KB |
Output is correct |
14 |
Correct |
113 ms |
10812 KB |
Output is correct |
15 |
Correct |
79 ms |
8180 KB |
Output is correct |
16 |
Correct |
92 ms |
6596 KB |
Output is correct |
17 |
Correct |
27 ms |
340 KB |
Output is correct |
18 |
Correct |
21 ms |
328 KB |
Output is correct |
19 |
Correct |
17 ms |
320 KB |
Output is correct |
20 |
Correct |
9 ms |
212 KB |
Output is correct |
21 |
Correct |
10 ms |
304 KB |
Output is correct |
22 |
Correct |
52 ms |
724 KB |
Output is correct |
23 |
Correct |
49 ms |
800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
596 KB |
Output is correct |
11 |
Correct |
316 ms |
26004 KB |
Output is correct |
12 |
Correct |
308 ms |
26084 KB |
Output is correct |
13 |
Correct |
183 ms |
26084 KB |
Output is correct |
14 |
Correct |
185 ms |
26116 KB |
Output is correct |
15 |
Correct |
1 ms |
216 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
164 ms |
16016 KB |
Output is correct |
24 |
Correct |
113 ms |
10812 KB |
Output is correct |
25 |
Correct |
79 ms |
8180 KB |
Output is correct |
26 |
Correct |
92 ms |
6596 KB |
Output is correct |
27 |
Correct |
27 ms |
340 KB |
Output is correct |
28 |
Correct |
21 ms |
328 KB |
Output is correct |
29 |
Correct |
17 ms |
320 KB |
Output is correct |
30 |
Correct |
9 ms |
212 KB |
Output is correct |
31 |
Correct |
10 ms |
304 KB |
Output is correct |
32 |
Correct |
52 ms |
724 KB |
Output is correct |
33 |
Correct |
49 ms |
800 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
130 ms |
27212 KB |
Output is correct |
36 |
Correct |
258 ms |
32644 KB |
Output is correct |
37 |
Correct |
303 ms |
31820 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
312 KB |
Output is correct |
44 |
Correct |
0 ms |
340 KB |
Output is correct |
45 |
Correct |
38 ms |
796 KB |
Output is correct |
46 |
Correct |
10 ms |
1236 KB |
Output is correct |
47 |
Correct |
7 ms |
420 KB |
Output is correct |
48 |
Correct |
49 ms |
5600 KB |
Output is correct |
49 |
Correct |
2 ms |
212 KB |
Output is correct |
50 |
Correct |
34 ms |
212 KB |
Output is correct |
51 |
Correct |
46 ms |
704 KB |
Output is correct |
52 |
Correct |
11 ms |
324 KB |
Output is correct |
53 |
Correct |
25 ms |
320 KB |
Output is correct |
54 |
Correct |
29 ms |
212 KB |
Output is correct |
55 |
Correct |
184 ms |
15888 KB |
Output is correct |
56 |
Correct |
104 ms |
10176 KB |
Output is correct |
57 |
Correct |
104 ms |
10172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
216 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
164 ms |
16016 KB |
Output is correct |
10 |
Correct |
113 ms |
10812 KB |
Output is correct |
11 |
Correct |
79 ms |
8180 KB |
Output is correct |
12 |
Correct |
92 ms |
6596 KB |
Output is correct |
13 |
Correct |
27 ms |
340 KB |
Output is correct |
14 |
Correct |
21 ms |
328 KB |
Output is correct |
15 |
Correct |
17 ms |
320 KB |
Output is correct |
16 |
Correct |
9 ms |
212 KB |
Output is correct |
17 |
Correct |
10 ms |
304 KB |
Output is correct |
18 |
Correct |
52 ms |
724 KB |
Output is correct |
19 |
Correct |
49 ms |
800 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
130 ms |
27212 KB |
Output is correct |
22 |
Correct |
258 ms |
32644 KB |
Output is correct |
23 |
Correct |
303 ms |
31820 KB |
Output is correct |
24 |
Incorrect |
45 ms |
1860 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
596 KB |
Output is correct |
11 |
Correct |
316 ms |
26004 KB |
Output is correct |
12 |
Correct |
308 ms |
26084 KB |
Output is correct |
13 |
Correct |
183 ms |
26084 KB |
Output is correct |
14 |
Correct |
185 ms |
26116 KB |
Output is correct |
15 |
Correct |
1 ms |
216 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
164 ms |
16016 KB |
Output is correct |
24 |
Correct |
113 ms |
10812 KB |
Output is correct |
25 |
Correct |
79 ms |
8180 KB |
Output is correct |
26 |
Correct |
92 ms |
6596 KB |
Output is correct |
27 |
Correct |
27 ms |
340 KB |
Output is correct |
28 |
Correct |
21 ms |
328 KB |
Output is correct |
29 |
Correct |
17 ms |
320 KB |
Output is correct |
30 |
Correct |
9 ms |
212 KB |
Output is correct |
31 |
Correct |
10 ms |
304 KB |
Output is correct |
32 |
Correct |
52 ms |
724 KB |
Output is correct |
33 |
Correct |
49 ms |
800 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
312 KB |
Output is correct |
40 |
Correct |
0 ms |
340 KB |
Output is correct |
41 |
Correct |
38 ms |
796 KB |
Output is correct |
42 |
Correct |
10 ms |
1236 KB |
Output is correct |
43 |
Correct |
7 ms |
420 KB |
Output is correct |
44 |
Correct |
49 ms |
5600 KB |
Output is correct |
45 |
Correct |
2 ms |
212 KB |
Output is correct |
46 |
Correct |
34 ms |
212 KB |
Output is correct |
47 |
Correct |
46 ms |
704 KB |
Output is correct |
48 |
Correct |
11 ms |
324 KB |
Output is correct |
49 |
Correct |
25 ms |
320 KB |
Output is correct |
50 |
Correct |
29 ms |
212 KB |
Output is correct |
51 |
Correct |
184 ms |
15888 KB |
Output is correct |
52 |
Correct |
104 ms |
10176 KB |
Output is correct |
53 |
Correct |
104 ms |
10172 KB |
Output is correct |
54 |
Incorrect |
45 ms |
1860 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |