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 longint32_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