#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
#define block_of_code if(true)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll gcd(ll a, ll b){return __gcd(a, b);}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
double rngesus_d(double l, double r){
double cur = rngesus(0, MASK(60) - 1);
cur /= MASK(60) - 1;
return l + cur * (r - l);
}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
for(auto item: container) out << item << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
const ll INF = 1e18;
ll di(ll a, ll b){
return a / b + ((a % b) > 0);
}
int main(void){
ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
clock_t start = clock();
int n; ll m; cin >> n >> m;
vector<ll> a(n), b(n);
for(int i = 0; i<n; ++i) cin >> a[i];
for(int i = 0; i<n; ++i) cin >> b[i];
ll l = 1, r = INF;
while(l < r){
ll mid = (l + r + 1) >> 1;
ll cnt = 0;
for(int i = 0; i<n; ++i){
ll cur = di(mid, max(a[i], b[i]));
if (cur <= m){
cnt += m - cur;
}
else{
ll fr = mid - max(a[i], b[i]) * m;
cnt -= di(fr, b[i]);
if (cnt <= -INF) maximize(cnt, -INF);
}
}
// if (check == false && cnt >= 0) exit(1);
if (cnt >= 0) l = mid;
else r = mid - 1;
}
cout << l << "\n";
cerr << "Time elapsed: " << clock() - start << " ms\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
110 ms |
10272 KB |
Output is correct |
12 |
Correct |
109 ms |
10324 KB |
Output is correct |
13 |
Correct |
111 ms |
8532 KB |
Output is correct |
14 |
Correct |
116 ms |
8528 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
109 ms |
6304 KB |
Output is correct |
17 |
Correct |
122 ms |
11348 KB |
Output is correct |
18 |
Correct |
112 ms |
10832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
109 ms |
6304 KB |
Output is correct |
3 |
Correct |
122 ms |
11348 KB |
Output is correct |
4 |
Correct |
112 ms |
10832 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
59 ms |
5356 KB |
Output is correct |
14 |
Correct |
39 ms |
3672 KB |
Output is correct |
15 |
Correct |
33 ms |
2908 KB |
Output is correct |
16 |
Correct |
26 ms |
2392 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
2 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
110 ms |
10272 KB |
Output is correct |
12 |
Correct |
109 ms |
10324 KB |
Output is correct |
13 |
Correct |
111 ms |
8532 KB |
Output is correct |
14 |
Correct |
116 ms |
8528 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
59 ms |
5356 KB |
Output is correct |
24 |
Correct |
39 ms |
3672 KB |
Output is correct |
25 |
Correct |
33 ms |
2908 KB |
Output is correct |
26 |
Correct |
26 ms |
2392 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
2 ms |
604 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
109 ms |
6304 KB |
Output is correct |
36 |
Correct |
122 ms |
11348 KB |
Output is correct |
37 |
Correct |
112 ms |
10832 KB |
Output is correct |
38 |
Correct |
1 ms |
344 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
428 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
460 KB |
Output is correct |
45 |
Correct |
3 ms |
604 KB |
Output is correct |
46 |
Correct |
4 ms |
604 KB |
Output is correct |
47 |
Correct |
1 ms |
600 KB |
Output is correct |
48 |
Correct |
20 ms |
2140 KB |
Output is correct |
49 |
Correct |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
2 ms |
604 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
1 ms |
348 KB |
Output is correct |
55 |
Correct |
57 ms |
5604 KB |
Output is correct |
56 |
Correct |
41 ms |
3412 KB |
Output is correct |
57 |
Correct |
37 ms |
3292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
59 ms |
5356 KB |
Output is correct |
10 |
Correct |
39 ms |
3672 KB |
Output is correct |
11 |
Correct |
33 ms |
2908 KB |
Output is correct |
12 |
Correct |
26 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
2 ms |
348 KB |
Output is correct |
19 |
Correct |
2 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
109 ms |
6304 KB |
Output is correct |
22 |
Correct |
122 ms |
11348 KB |
Output is correct |
23 |
Correct |
112 ms |
10832 KB |
Output is correct |
24 |
Correct |
16 ms |
2136 KB |
Output is correct |
25 |
Correct |
53 ms |
4956 KB |
Output is correct |
26 |
Correct |
13 ms |
1372 KB |
Output is correct |
27 |
Correct |
121 ms |
10900 KB |
Output is correct |
28 |
Correct |
122 ms |
10836 KB |
Output is correct |
29 |
Correct |
117 ms |
10832 KB |
Output is correct |
30 |
Correct |
138 ms |
10904 KB |
Output is correct |
31 |
Correct |
99 ms |
10836 KB |
Output is correct |
32 |
Correct |
99 ms |
6232 KB |
Output is correct |
33 |
Correct |
87 ms |
11424 KB |
Output is correct |
34 |
Correct |
104 ms |
6168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
604 KB |
Output is correct |
11 |
Correct |
110 ms |
10272 KB |
Output is correct |
12 |
Correct |
109 ms |
10324 KB |
Output is correct |
13 |
Correct |
111 ms |
8532 KB |
Output is correct |
14 |
Correct |
116 ms |
8528 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
59 ms |
5356 KB |
Output is correct |
24 |
Correct |
39 ms |
3672 KB |
Output is correct |
25 |
Correct |
33 ms |
2908 KB |
Output is correct |
26 |
Correct |
26 ms |
2392 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
33 |
Correct |
2 ms |
604 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
428 KB |
Output is correct |
38 |
Correct |
1 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
460 KB |
Output is correct |
41 |
Correct |
3 ms |
604 KB |
Output is correct |
42 |
Correct |
4 ms |
604 KB |
Output is correct |
43 |
Correct |
1 ms |
600 KB |
Output is correct |
44 |
Correct |
20 ms |
2140 KB |
Output is correct |
45 |
Correct |
1 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
2 ms |
604 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
57 ms |
5604 KB |
Output is correct |
52 |
Correct |
41 ms |
3412 KB |
Output is correct |
53 |
Correct |
37 ms |
3292 KB |
Output is correct |
54 |
Correct |
16 ms |
2136 KB |
Output is correct |
55 |
Correct |
53 ms |
4956 KB |
Output is correct |
56 |
Correct |
13 ms |
1372 KB |
Output is correct |
57 |
Correct |
121 ms |
10900 KB |
Output is correct |
58 |
Correct |
122 ms |
10836 KB |
Output is correct |
59 |
Correct |
117 ms |
10832 KB |
Output is correct |
60 |
Correct |
138 ms |
10904 KB |
Output is correct |
61 |
Correct |
99 ms |
10836 KB |
Output is correct |
62 |
Correct |
99 ms |
6232 KB |
Output is correct |
63 |
Correct |
87 ms |
11424 KB |
Output is correct |
64 |
Correct |
104 ms |
6168 KB |
Output is correct |
65 |
Correct |
1 ms |
344 KB |
Output is correct |
66 |
Correct |
109 ms |
6304 KB |
Output is correct |
67 |
Correct |
122 ms |
11348 KB |
Output is correct |
68 |
Correct |
112 ms |
10832 KB |
Output is correct |
69 |
Correct |
12 ms |
1368 KB |
Output is correct |
70 |
Correct |
4 ms |
600 KB |
Output is correct |
71 |
Correct |
1 ms |
348 KB |
Output is correct |
72 |
Correct |
18 ms |
1884 KB |
Output is correct |
73 |
Correct |
4 ms |
604 KB |
Output is correct |
74 |
Correct |
1 ms |
344 KB |
Output is correct |
75 |
Correct |
117 ms |
10780 KB |
Output is correct |
76 |
Correct |
118 ms |
10836 KB |
Output is correct |
77 |
Correct |
121 ms |
10960 KB |
Output is correct |
78 |
Correct |
128 ms |
10832 KB |
Output is correct |
79 |
Correct |
112 ms |
10844 KB |
Output is correct |
80 |
Correct |
100 ms |
10908 KB |
Output is correct |
81 |
Correct |
74 ms |
8784 KB |
Output is correct |
82 |
Correct |
75 ms |
8788 KB |
Output is correct |