cses

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

factory_machines.cpp (782B)


      1 #include <bits/stdc++.h>
      2 
      3 using namespace std;
      4 
      5 using ui = unsigned int;
      6 using l = long;
      7 using ul = unsigned long;
      8 using ll = long long;
      9 using ull = unsigned long long;
     10 
     11 using vi = vector<int>;
     12 using vui = vector<ui>;
     13 using vl = vector<l>;
     14 using vul = vector<ul>;
     15 using vll = vector<ll>;
     16 using vull = vector<ull>;
     17 
     18 void solve()
     19 {
     20 	int n, t;
     21 	cin >> n >> t;
     22 	l mx = 0;
     23 	l k[n];
     24 	for (int i = 0; i < n; i++) {
     25 		cin >> k[i];
     26 		mx = max(mx, k[i]);
     27 	}
     28 	long l = 0, r = mx * t, m, res = 0;
     29 
     30 	while (l <= r) {
     31 		m = (l + r) / 2;
     32 		long s = 0;
     33 		for (int i = 0; i < n; i++) {
     34 			s += m / k[i];
     35 			if (s >= t) {
     36 				break;
     37 			}
     38 		}
     39 		if (s < t) {
     40 			l = m+1;
     41 		} else {
     42 			res = m;
     43 			r = m-1;
     44 		}
     45 	}
     46 	cout << res << "\n";
     47 }
     48 
     49 int main()
     50 {
     51 	ios::sync_with_stdio(0);
     52 	cin.tie(0);
     53 	solve();
     54 }