#include <iostream>
#include <fstream>
#define int unsigned long long
using namespace std;
const int nmax=3e5+5;
int n, m, a[nmax], b[nmax];
bool check (int val)
{
int days=n*m;
for (int i=1;i<=n;i++)
{
int filled=0;
if (a[i]>b[i])
{
int nr_act=min (days, m);
if (nr_act*a[i]<val)
{
days-=nr_act;
filled=nr_act*a[i];
}
else
{
days-=val/a[i]+(val%a[i]!=0);
continue;
}
}
int nr_act=days;
if (nr_act*b[i]<val-filled)
{
return 0;
}
days-=(val-filled)/b[i]+((val-filled)%b[i]!=0);
if (days<0)
{
return 0;
}
}
return 1;
}
int32_t main()
{
cin >> n >> m;
for (int i=1;i<=n;i++)
{
cin >> a[i];
}
for (int i=1;i<=n;i++)
{
cin >> b[i];
}
int st=0, dr=1e18, poz=0;
while (st<=dr)
{
int mij = (st+dr) >> 1;
if (check (mij))
{
st=mij+1;
poz=mij;
}
else dr=mij-1;
}
cout << poz;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2448 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
3 ms |
2396 KB |
Output is correct |
11 |
Correct |
195 ms |
5280 KB |
Output is correct |
12 |
Correct |
181 ms |
5028 KB |
Output is correct |
13 |
Correct |
114 ms |
4944 KB |
Output is correct |
14 |
Correct |
115 ms |
4944 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
48 ms |
4948 KB |
Output is correct |
17 |
Correct |
162 ms |
4948 KB |
Output is correct |
18 |
Correct |
152 ms |
5024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
48 ms |
4948 KB |
Output is correct |
3 |
Correct |
162 ms |
4948 KB |
Output is correct |
4 |
Correct |
152 ms |
5024 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 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 |
85 ms |
4532 KB |
Output is correct |
14 |
Correct |
66 ms |
4692 KB |
Output is correct |
15 |
Correct |
38 ms |
4536 KB |
Output is correct |
16 |
Correct |
32 ms |
4696 KB |
Output is correct |
17 |
Correct |
1 ms |
2392 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2444 KB |
Output is correct |
21 |
Correct |
0 ms |
2396 KB |
Output is correct |
22 |
Correct |
1 ms |
2396 KB |
Output is correct |
23 |
Correct |
3 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2448 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
3 ms |
2396 KB |
Output is correct |
11 |
Correct |
195 ms |
5280 KB |
Output is correct |
12 |
Correct |
181 ms |
5028 KB |
Output is correct |
13 |
Correct |
114 ms |
4944 KB |
Output is correct |
14 |
Correct |
115 ms |
4944 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 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 |
85 ms |
4532 KB |
Output is correct |
24 |
Correct |
66 ms |
4692 KB |
Output is correct |
25 |
Correct |
38 ms |
4536 KB |
Output is correct |
26 |
Correct |
32 ms |
4696 KB |
Output is correct |
27 |
Correct |
1 ms |
2392 KB |
Output is correct |
28 |
Correct |
0 ms |
2396 KB |
Output is correct |
29 |
Correct |
0 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2444 KB |
Output is correct |
31 |
Correct |
0 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
3 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
48 ms |
4948 KB |
Output is correct |
36 |
Correct |
162 ms |
4948 KB |
Output is correct |
37 |
Correct |
152 ms |
5024 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 |
0 ms |
2396 KB |
Output is correct |
42 |
Correct |
0 ms |
2392 KB |
Output is correct |
43 |
Correct |
0 ms |
2396 KB |
Output is correct |
44 |
Correct |
0 ms |
2392 KB |
Output is correct |
45 |
Correct |
3 ms |
2396 KB |
Output is correct |
46 |
Correct |
6 ms |
2396 KB |
Output is correct |
47 |
Correct |
1 ms |
2396 KB |
Output is correct |
48 |
Correct |
31 ms |
4660 KB |
Output is correct |
49 |
Correct |
0 ms |
2396 KB |
Output is correct |
50 |
Correct |
0 ms |
2396 KB |
Output is correct |
51 |
Correct |
3 ms |
2460 KB |
Output is correct |
52 |
Correct |
0 ms |
2396 KB |
Output is correct |
53 |
Correct |
1 ms |
2440 KB |
Output is correct |
54 |
Correct |
0 ms |
2396 KB |
Output is correct |
55 |
Correct |
96 ms |
4532 KB |
Output is correct |
56 |
Correct |
39 ms |
4696 KB |
Output is correct |
57 |
Correct |
37 ms |
4688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
0 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 |
85 ms |
4532 KB |
Output is correct |
10 |
Correct |
66 ms |
4692 KB |
Output is correct |
11 |
Correct |
38 ms |
4536 KB |
Output is correct |
12 |
Correct |
32 ms |
4696 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
0 ms |
2396 KB |
Output is correct |
15 |
Correct |
0 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2444 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
3 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
48 ms |
4948 KB |
Output is correct |
22 |
Correct |
162 ms |
4948 KB |
Output is correct |
23 |
Correct |
152 ms |
5024 KB |
Output is correct |
24 |
Incorrect |
26 ms |
4700 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2448 KB |
Output is correct |
7 |
Correct |
0 ms |
2396 KB |
Output is correct |
8 |
Correct |
0 ms |
2396 KB |
Output is correct |
9 |
Correct |
0 ms |
2396 KB |
Output is correct |
10 |
Correct |
3 ms |
2396 KB |
Output is correct |
11 |
Correct |
195 ms |
5280 KB |
Output is correct |
12 |
Correct |
181 ms |
5028 KB |
Output is correct |
13 |
Correct |
114 ms |
4944 KB |
Output is correct |
14 |
Correct |
115 ms |
4944 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
0 ms |
2396 KB |
Output is correct |
17 |
Correct |
0 ms |
2396 KB |
Output is correct |
18 |
Correct |
0 ms |
2396 KB |
Output is correct |
19 |
Correct |
0 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 |
85 ms |
4532 KB |
Output is correct |
24 |
Correct |
66 ms |
4692 KB |
Output is correct |
25 |
Correct |
38 ms |
4536 KB |
Output is correct |
26 |
Correct |
32 ms |
4696 KB |
Output is correct |
27 |
Correct |
1 ms |
2392 KB |
Output is correct |
28 |
Correct |
0 ms |
2396 KB |
Output is correct |
29 |
Correct |
0 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2444 KB |
Output is correct |
31 |
Correct |
0 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
3 ms |
2396 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 |
0 ms |
2396 KB |
Output is correct |
38 |
Correct |
0 ms |
2392 KB |
Output is correct |
39 |
Correct |
0 ms |
2396 KB |
Output is correct |
40 |
Correct |
0 ms |
2392 KB |
Output is correct |
41 |
Correct |
3 ms |
2396 KB |
Output is correct |
42 |
Correct |
6 ms |
2396 KB |
Output is correct |
43 |
Correct |
1 ms |
2396 KB |
Output is correct |
44 |
Correct |
31 ms |
4660 KB |
Output is correct |
45 |
Correct |
0 ms |
2396 KB |
Output is correct |
46 |
Correct |
0 ms |
2396 KB |
Output is correct |
47 |
Correct |
3 ms |
2460 KB |
Output is correct |
48 |
Correct |
0 ms |
2396 KB |
Output is correct |
49 |
Correct |
1 ms |
2440 KB |
Output is correct |
50 |
Correct |
0 ms |
2396 KB |
Output is correct |
51 |
Correct |
96 ms |
4532 KB |
Output is correct |
52 |
Correct |
39 ms |
4696 KB |
Output is correct |
53 |
Correct |
37 ms |
4688 KB |
Output is correct |
54 |
Incorrect |
26 ms |
4700 KB |
Output isn't correct |
55 |
Halted |
0 ms |
0 KB |
- |