/**
____ ____ ____ ____ ____ ____
||l |||e |||i |||n |||a |||d ||
||__|||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|/__\|
**/
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const ll maxn = 300010;
ll n, m;
ll a[maxn], b[maxn], in[maxn], out[maxn], cp[maxn];
bool check(ll mf)
{
ll nec = 0, op = n * m;
for (int i = 1; i <= n; i ++)
{
if (a[i] >= b[i])
{
ll loc = mf / a[i];
if (mf % a[i] != 0)
loc ++;
ll to_use = min(m, loc);
op = op - to_use;
nec = nec + max((ll)0, (mf - to_use * a[i])) / b[i];
if ( max((ll)0, (mf - to_use * a[i])) % b[i] != 0)
nec ++;
}
else
{
nec = nec + mf / b[i];
if (mf % b[i] != 0)
nec ++;
}
///cout << i << " " << nec << endl;
}
return nec <= op;
}
void solve()
{
cin >> n >> m;
bool diff = false;
for (ll i = 1; i <= n; i ++)
cin >> a[i];
for (ll i = 1; i <= n; i ++)
{
cin >> b[i];
if (b[i] != a[i])
diff = true;
}
ll m1 = 1e18;
for (int i = 1; i <= n; i ++)
m1= min(m1, max(a[i], b[i]));
double sum = 0;
for (int i = 1; i <= n; i ++)
sum = sum + (double)m / (double)(n) * (double)a[i];
ll lf = 0, rf = ceil(sum);
while(lf <= rf)
{
ll mf = (lf + rf) / 2;
if (check(mf))
lf = mf + 1;
else
rf = mf - 1;
}
if (rf < m1)
while(true);
cout << rf << endl;
}
int main()
{
solve();
return 0;
}
Compilation message
Main.cpp: In function 'void solve()':
Main.cpp:68:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
68 | for (int i = 1; i <= n; i ++)
| ^~~
Main.cpp:71:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
71 | double sum = 0;
| ^~~~~~
Main.cpp:58:10: warning: variable 'diff' set but not used [-Wunused-but-set-variable]
58 | bool diff = false;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1098 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
142 ms |
2684 KB |
Output is correct |
10 |
Correct |
86 ms |
1868 KB |
Output is correct |
11 |
Correct |
63 ms |
1436 KB |
Output is correct |
12 |
Correct |
53 ms |
1232 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
5 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
75 ms |
4980 KB |
Output is correct |
22 |
Correct |
269 ms |
5004 KB |
Output is correct |
23 |
Correct |
245 ms |
4988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1098 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
142 ms |
2684 KB |
Output is correct |
10 |
Correct |
86 ms |
1868 KB |
Output is correct |
11 |
Correct |
63 ms |
1436 KB |
Output is correct |
12 |
Correct |
53 ms |
1232 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
5 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
75 ms |
4980 KB |
Output is correct |
22 |
Correct |
269 ms |
5004 KB |
Output is correct |
23 |
Correct |
245 ms |
4988 KB |
Output is correct |
24 |
Correct |
61 ms |
936 KB |
Output is correct |
25 |
Correct |
148 ms |
2396 KB |
Output is correct |
26 |
Correct |
42 ms |
704 KB |
Output is correct |
27 |
Correct |
250 ms |
4976 KB |
Output is correct |
28 |
Correct |
264 ms |
4916 KB |
Output is correct |
29 |
Correct |
253 ms |
4928 KB |
Output is correct |
30 |
Correct |
291 ms |
5064 KB |
Output is correct |
31 |
Correct |
382 ms |
4944 KB |
Output is correct |
32 |
Correct |
156 ms |
4880 KB |
Output is correct |
33 |
Correct |
414 ms |
4984 KB |
Output is correct |
34 |
Correct |
270 ms |
4928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1098 ms |
212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |