CSES - Factory Machines

Author: Michael Cao

In this problem, you're given machines and asked the minimum time these machines need to work to create products such that the -th machine creates a product in time.

Binary Search

Observe that the time needed to create at least products is monotonic. In other words, if the given machines can create products in time, then the same machines can create at least products in time. Using this property, we can binary search over the answer. Read this module for more information.

For some value we binary search for, , we are left with the task of checking whether we can create products in time. To do this, observe that it's optimal for every machine to work simultaneously. Then, in time, machine can create products.

Overall, the machines can create ‎‎ products. If this sum , then is valid.

1#include <bits/stdc++.h>
2using namespace std;
3using ll = long long;
4using vi = vector<int>;
5#define pb push_back
6#define rsz resize
7#define all(x) begin(x), end(x)
8#define sz(x) (int)(x).size()
9using pi = pair<int,int>;
10#define f first

Join the USACO Forum!

Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!

Give Us Feedback on CSES - Factory Machines!