#include<bits/stdc++.h>
#define fo(i,l,r) for(int i = l; i <= r; i++)
#define fod(i,r,l) for(int i = r ; i >= l; i--)
#define int long long
#define maxn 1000010
#define N 1010
#define inf (int)3e18
#define pb emplace_back
#define all(x) x.begin(),x.end()
#define en cout << "\n";
#define ss(x) (int)x.size()
#define bitcount(x) __builtint_popcountll(x)
#define bit(x,i) ((x >> i) & 1)
#define onbit(x,i) (x | (1ll << i))
#define offbit(x,i) (x ^ (1ll << i))
#define lb(x) x & -x
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define fi first
#define se second
bool maximize(int &a,int b)
{
if(a <= b)
{
a = b;
return 1;
}
return 0;
}
bool minimize(int &a,int b)
{
if(a >= b)
{
a = b;
return 1;
}
return 0;
}
using namespace std;
int n,m;
int a[maxn],b[maxn];
namespace sub3
{
bool check(int x)
{
int r = 0;
fo(i,1,n)
{
int val = x / a[i] + (x % a[i] > 0);
if(val <= m) r += m - val;
else
{
int cc = x - m * a[i];
cc = cc / b[i] + (cc % b[i] > 0);
r -= cc;
if(r < -1e18) return 0;
}
}
return r >= 0;
}
void solve()
{
fo(i,1,n) a[i] = max(a[i],b[i]);
int l = 0,r = inf,ans = 0;
while(l <= r)
{
int mid = l + r >> 1;
if(check(mid)) ans = mid,l = mid + 1;
else r = mid - 1;
}
cout << ans;
}
}
main()
{
#define name "TASK"
if(fopen(name".inp","r"))
{
freopen(name".inp","r",stdin);
freopen(name".out","w",stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
fo(i,1,n) cin >> a[i];
fo(i,1,n) cin >> b[i];
sub3::solve();
}
Compilation message
Main.cpp: In function 'void sub3::solve()':
Main.cpp:68:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
68 | int mid = l + r >> 1;
| ~~^~~
Main.cpp: At global scope:
Main.cpp:75:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
75 | main()
| ^~~~
Main.cpp: In function 'int main()':
Main.cpp:80:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
80 | freopen(name".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
81 | freopen(name".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
2 ms |
2396 KB |
Output is correct |
11 |
Correct |
109 ms |
8820 KB |
Output is correct |
12 |
Correct |
107 ms |
8840 KB |
Output is correct |
13 |
Correct |
107 ms |
8820 KB |
Output is correct |
14 |
Correct |
112 ms |
9040 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
79 ms |
8824 KB |
Output is correct |
17 |
Correct |
123 ms |
8788 KB |
Output is correct |
18 |
Correct |
110 ms |
8784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
79 ms |
8824 KB |
Output is correct |
3 |
Correct |
123 ms |
8788 KB |
Output is correct |
4 |
Correct |
110 ms |
8784 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2516 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
0 ms |
2396 KB |
Output is correct |
13 |
Correct |
57 ms |
6608 KB |
Output is correct |
14 |
Correct |
38 ms |
6744 KB |
Output is correct |
15 |
Correct |
28 ms |
6748 KB |
Output is correct |
16 |
Correct |
24 ms |
4700 KB |
Output is correct |
17 |
Correct |
2 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2392 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2648 KB |
Output is correct |
22 |
Correct |
3 ms |
2392 KB |
Output is correct |
23 |
Correct |
3 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
2 ms |
2396 KB |
Output is correct |
11 |
Correct |
109 ms |
8820 KB |
Output is correct |
12 |
Correct |
107 ms |
8840 KB |
Output is correct |
13 |
Correct |
107 ms |
8820 KB |
Output is correct |
14 |
Correct |
112 ms |
9040 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2516 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
0 ms |
2396 KB |
Output is correct |
23 |
Correct |
57 ms |
6608 KB |
Output is correct |
24 |
Correct |
38 ms |
6744 KB |
Output is correct |
25 |
Correct |
28 ms |
6748 KB |
Output is correct |
26 |
Correct |
24 ms |
4700 KB |
Output is correct |
27 |
Correct |
2 ms |
2396 KB |
Output is correct |
28 |
Correct |
0 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2392 KB |
Output is correct |
30 |
Correct |
0 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2648 KB |
Output is correct |
32 |
Correct |
3 ms |
2392 KB |
Output is correct |
33 |
Correct |
3 ms |
2392 KB |
Output is correct |
34 |
Correct |
1 ms |
2392 KB |
Output is correct |
35 |
Correct |
79 ms |
8824 KB |
Output is correct |
36 |
Correct |
123 ms |
8788 KB |
Output is correct |
37 |
Correct |
110 ms |
8784 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
0 ms |
2396 KB |
Output is correct |
40 |
Correct |
0 ms |
2396 KB |
Output is correct |
41 |
Correct |
1 ms |
2396 KB |
Output is correct |
42 |
Correct |
1 ms |
2396 KB |
Output is correct |
43 |
Correct |
0 ms |
2396 KB |
Output is correct |
44 |
Correct |
0 ms |
2392 KB |
Output is correct |
45 |
Correct |
2 ms |
2396 KB |
Output is correct |
46 |
Correct |
4 ms |
2396 KB |
Output is correct |
47 |
Correct |
1 ms |
2396 KB |
Output is correct |
48 |
Correct |
20 ms |
4740 KB |
Output is correct |
49 |
Correct |
0 ms |
2396 KB |
Output is correct |
50 |
Correct |
1 ms |
2392 KB |
Output is correct |
51 |
Correct |
2 ms |
2396 KB |
Output is correct |
52 |
Correct |
0 ms |
2396 KB |
Output is correct |
53 |
Correct |
0 ms |
2396 KB |
Output is correct |
54 |
Correct |
0 ms |
2396 KB |
Output is correct |
55 |
Correct |
55 ms |
6608 KB |
Output is correct |
56 |
Correct |
36 ms |
6748 KB |
Output is correct |
57 |
Correct |
33 ms |
6748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2516 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
57 ms |
6608 KB |
Output is correct |
10 |
Correct |
38 ms |
6744 KB |
Output is correct |
11 |
Correct |
28 ms |
6748 KB |
Output is correct |
12 |
Correct |
24 ms |
4700 KB |
Output is correct |
13 |
Correct |
2 ms |
2396 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2648 KB |
Output is correct |
18 |
Correct |
3 ms |
2392 KB |
Output is correct |
19 |
Correct |
3 ms |
2392 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
79 ms |
8824 KB |
Output is correct |
22 |
Correct |
123 ms |
8788 KB |
Output is correct |
23 |
Correct |
110 ms |
8784 KB |
Output is correct |
24 |
Correct |
17 ms |
4700 KB |
Output is correct |
25 |
Correct |
50 ms |
6616 KB |
Output is correct |
26 |
Correct |
14 ms |
4696 KB |
Output is correct |
27 |
Correct |
117 ms |
8820 KB |
Output is correct |
28 |
Correct |
117 ms |
8820 KB |
Output is correct |
29 |
Correct |
115 ms |
8820 KB |
Output is correct |
30 |
Correct |
118 ms |
8784 KB |
Output is correct |
31 |
Correct |
101 ms |
8824 KB |
Output is correct |
32 |
Correct |
71 ms |
8796 KB |
Output is correct |
33 |
Correct |
110 ms |
8784 KB |
Output is correct |
34 |
Correct |
81 ms |
9844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
2 ms |
2396 KB |
Output is correct |
11 |
Correct |
109 ms |
8820 KB |
Output is correct |
12 |
Correct |
107 ms |
8840 KB |
Output is correct |
13 |
Correct |
107 ms |
8820 KB |
Output is correct |
14 |
Correct |
112 ms |
9040 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2516 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
0 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2396 KB |
Output is correct |
22 |
Correct |
0 ms |
2396 KB |
Output is correct |
23 |
Correct |
57 ms |
6608 KB |
Output is correct |
24 |
Correct |
38 ms |
6744 KB |
Output is correct |
25 |
Correct |
28 ms |
6748 KB |
Output is correct |
26 |
Correct |
24 ms |
4700 KB |
Output is correct |
27 |
Correct |
2 ms |
2396 KB |
Output is correct |
28 |
Correct |
0 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2392 KB |
Output is correct |
30 |
Correct |
0 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2648 KB |
Output is correct |
32 |
Correct |
3 ms |
2392 KB |
Output is correct |
33 |
Correct |
3 ms |
2392 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
0 ms |
2396 KB |
Output is correct |
36 |
Correct |
0 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
0 ms |
2396 KB |
Output is correct |
40 |
Correct |
0 ms |
2392 KB |
Output is correct |
41 |
Correct |
2 ms |
2396 KB |
Output is correct |
42 |
Correct |
4 ms |
2396 KB |
Output is correct |
43 |
Correct |
1 ms |
2396 KB |
Output is correct |
44 |
Correct |
20 ms |
4740 KB |
Output is correct |
45 |
Correct |
0 ms |
2396 KB |
Output is correct |
46 |
Correct |
1 ms |
2392 KB |
Output is correct |
47 |
Correct |
2 ms |
2396 KB |
Output is correct |
48 |
Correct |
0 ms |
2396 KB |
Output is correct |
49 |
Correct |
0 ms |
2396 KB |
Output is correct |
50 |
Correct |
0 ms |
2396 KB |
Output is correct |
51 |
Correct |
55 ms |
6608 KB |
Output is correct |
52 |
Correct |
36 ms |
6748 KB |
Output is correct |
53 |
Correct |
33 ms |
6748 KB |
Output is correct |
54 |
Correct |
17 ms |
4700 KB |
Output is correct |
55 |
Correct |
50 ms |
6616 KB |
Output is correct |
56 |
Correct |
14 ms |
4696 KB |
Output is correct |
57 |
Correct |
117 ms |
8820 KB |
Output is correct |
58 |
Correct |
117 ms |
8820 KB |
Output is correct |
59 |
Correct |
115 ms |
8820 KB |
Output is correct |
60 |
Correct |
118 ms |
8784 KB |
Output is correct |
61 |
Correct |
101 ms |
8824 KB |
Output is correct |
62 |
Correct |
71 ms |
8796 KB |
Output is correct |
63 |
Correct |
110 ms |
8784 KB |
Output is correct |
64 |
Correct |
81 ms |
9844 KB |
Output is correct |
65 |
Correct |
1 ms |
2392 KB |
Output is correct |
66 |
Correct |
79 ms |
8824 KB |
Output is correct |
67 |
Correct |
123 ms |
8788 KB |
Output is correct |
68 |
Correct |
110 ms |
8784 KB |
Output is correct |
69 |
Correct |
13 ms |
5212 KB |
Output is correct |
70 |
Correct |
4 ms |
2652 KB |
Output is correct |
71 |
Correct |
1 ms |
2396 KB |
Output is correct |
72 |
Correct |
17 ms |
5464 KB |
Output is correct |
73 |
Correct |
4 ms |
2652 KB |
Output is correct |
74 |
Correct |
1 ms |
2400 KB |
Output is correct |
75 |
Correct |
118 ms |
14524 KB |
Output is correct |
76 |
Correct |
115 ms |
14420 KB |
Output is correct |
77 |
Correct |
119 ms |
14416 KB |
Output is correct |
78 |
Correct |
116 ms |
14416 KB |
Output is correct |
79 |
Correct |
116 ms |
14436 KB |
Output is correct |
80 |
Correct |
106 ms |
14416 KB |
Output is correct |
81 |
Correct |
102 ms |
12628 KB |
Output is correct |
82 |
Correct |
89 ms |
12624 KB |
Output is correct |