#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
const int nmax = 3e5 + 7;
int v[nmax], b[nmax], cnt[nmax], n, k;
long long unu = 1;
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(long long x) {
long long sum = 0;
for(int i = 1; i <= n; i ++) {
long long curr = x / v[i];
if(v[i] * curr < x) {
curr ++;
}
sum += curr;
}
if(sum <= n * k) {
return 1;
}
return 0;
}
int32_t main() {
int test = 1;
cin >> n >> k;
for(int i = 1; i <= n; i ++) {
cin >> v[i];
}
for(int i = 1; i <= n; i ++){
cin >> b[i];
if(v[i] != b[i]) {
test = 1;
}
}
if(!test) {
long long l = 0, r = 1e18;
while(l < r) {
long long mid = (l + r) / 2;
if(check(mid) == 1) {
l = mid + 1;
} else {
r = mid - 1;
}
}
cout << max(unu, 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;
}
Compilation message
Main.cpp: In function 'int32_t main()':
Main.cpp:82:16: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
82 | int minn = 1e18;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
267 ms |
17800 KB |
Output is correct |
12 |
Correct |
275 ms |
17864 KB |
Output is correct |
13 |
Correct |
177 ms |
17816 KB |
Output is correct |
14 |
Correct |
176 ms |
17868 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
128 ms |
17968 KB |
Output is correct |
17 |
Correct |
235 ms |
17816 KB |
Output is correct |
18 |
Correct |
313 ms |
17772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
128 ms |
17968 KB |
Output is correct |
3 |
Correct |
235 ms |
17816 KB |
Output is correct |
4 |
Correct |
313 ms |
17772 KB |
Output is correct |
5 |
Correct |
0 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 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
267 ms |
17800 KB |
Output is correct |
12 |
Correct |
275 ms |
17864 KB |
Output is correct |
13 |
Correct |
177 ms |
17816 KB |
Output is correct |
14 |
Correct |
176 ms |
17868 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
267 ms |
17800 KB |
Output is correct |
12 |
Correct |
275 ms |
17864 KB |
Output is correct |
13 |
Correct |
177 ms |
17816 KB |
Output is correct |
14 |
Correct |
176 ms |
17868 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |