CSES Problem Set Factory Machines Solution



 Problem Link:  https://cses.fi/problemset/task/1620

Solution in C++:

/// Author : AH_Tonmoy
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int low = 0, high = 1e18;
int ans = 0, cnt = 0;
while (low <= high) {
int mid = (high + low) / 2;
int sum = 0;
for (int i = 0; i < n; i++) {
sum += (mid / a[i]);
if (sum >= k) break;
}
if (sum >= k) {
ans = mid;
high = mid - 1;
} else {
low = mid + 1;
}
}
cout << ans << '\n';
return 0;
}

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.