cses

solution to cses exercise problems
git clone git://git.superpozycja.net/cses
Log | Files | Refs | README

commit be6921d998c3d43e2eb5182c057c868ff66a7b5e
parent 947266b94296cf7a6438ad152b878bfb143f905b
Author: superpozycja <anna@superpozycja.net>
Date:   Fri,  1 Nov 2024 23:10:42 +0100

solve factory machines

Diffstat:
Asorting_and_searching/factory_machines.cpp | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+), 0 deletions(-)

diff --git a/sorting_and_searching/factory_machines.cpp b/sorting_and_searching/factory_machines.cpp @@ -0,0 +1,54 @@ +#include <bits/stdc++.h> + +using namespace std; + +using ui = unsigned int; +using l = long; +using ul = unsigned long; +using ll = long long; +using ull = unsigned long long; + +using vi = vector<int>; +using vui = vector<ui>; +using vl = vector<l>; +using vul = vector<ul>; +using vll = vector<ll>; +using vull = vector<ull>; + +void solve() +{ + int n, t; + cin >> n >> t; + l mx = 0; + l k[n]; + for (int i = 0; i < n; i++) { + cin >> k[i]; + mx = max(mx, k[i]); + } + long l = 0, r = mx * t, m, res = 0; + + while (l <= r) { + m = (l + r) / 2; + long s = 0; + for (int i = 0; i < n; i++) { + s += m / k[i]; + if (s >= t) { + break; + } + } + if (s < t) { + l = m+1; + } else { + res = m; + r = m-1; + } + } + cout << res << "\n"; +} + +int main() +{ + ios::sync_with_stdio(0); + cin.tie(0); + solve(); +}