#include<bits/stdc++.h>
using namespace std;
#pragma gcc optimize('ofast','unroll-loops')
#define endl '\n'
#define ff first
#define ss second
#define pb emplace_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define rep(a,b,c) for(int a=b;a<c;a++)
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
const ll maxn = 300005;
const ll maxm = 200005;
const ll mod = 1000000007;
void solve(){
ll n, m;
ll arr[maxn];
ll brr[maxn];
cin >> n >> m;
rep(i,0,n) cin >> arr[i];
rep(i,0,n) cin >> brr[i], arr[i] = max(arr[i],brr[i]);
ll l = 0;
ll r = 100000000000000000;
while(l+1<r){
ll mid = (l+r>>1);
ll ac = 0;
//cout<<mid<<endl;
rep(i,0,n){
if(arr[i]*m>=mid) ac += (mid-1)/arr[i]+1;
else ac += m+(mid-arr[i]*m-1)/brr[i]+1;
//cout << ac << ' ';
}//cout<<endl;
if(ac>n*m) r = mid;
else l = mid;
}
//cout<<(-1)/2<<endl;//int mid=18,ac=0;rep(i,0,n){if(arr[i]*m>=mid)ac-=m-(mid-1)/arr[i]-1;else ac+=(mid-arr[i]*m-1)/brr[i]+1;}cout<<ac<<endl;
cout << l << endl;
}
int main(){
//freopen("input.txt","r",stdin);
//freopen("sol.txt","w",stdout);
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
//cin >> t;
while(t--) solve();
}
Compilation message
Main.cpp:4: warning: ignoring '#pragma gcc optimize' [-Wunknown-pragmas]
4 | #pragma gcc optimize('ofast','unroll-loops')
|
Main.cpp: In function 'void solve()':
Main.cpp:36:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
36 | ll mid = (l+r>>1);
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
6 ms |
4948 KB |
Output is correct |
11 |
Correct |
152 ms |
4948 KB |
Output is correct |
12 |
Correct |
150 ms |
4948 KB |
Output is correct |
13 |
Correct |
144 ms |
4992 KB |
Output is correct |
14 |
Incorrect |
277 ms |
5000 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4968 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
76 ms |
4948 KB |
Output is correct |
10 |
Correct |
52 ms |
4948 KB |
Output is correct |
11 |
Correct |
39 ms |
4948 KB |
Output is correct |
12 |
Correct |
33 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
2 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
4948 KB |
Output is correct |
18 |
Incorrect |
7 ms |
4948 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
6 ms |
4948 KB |
Output is correct |
11 |
Correct |
152 ms |
4948 KB |
Output is correct |
12 |
Correct |
150 ms |
4948 KB |
Output is correct |
13 |
Correct |
144 ms |
4992 KB |
Output is correct |
14 |
Incorrect |
277 ms |
5000 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4968 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
76 ms |
4948 KB |
Output is correct |
10 |
Correct |
52 ms |
4948 KB |
Output is correct |
11 |
Correct |
39 ms |
4948 KB |
Output is correct |
12 |
Correct |
33 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
2 ms |
4948 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
2 ms |
4948 KB |
Output is correct |
18 |
Incorrect |
7 ms |
4948 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4948 KB |
Output is correct |
9 |
Correct |
2 ms |
4948 KB |
Output is correct |
10 |
Correct |
6 ms |
4948 KB |
Output is correct |
11 |
Correct |
152 ms |
4948 KB |
Output is correct |
12 |
Correct |
150 ms |
4948 KB |
Output is correct |
13 |
Correct |
144 ms |
4992 KB |
Output is correct |
14 |
Incorrect |
277 ms |
5000 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |