Skip to content

Commit 96e5f7f

Browse files
Merge pull request #5184 from Sosuke23/fix
update Factory machines
2 parents 5b1fdac + 791abe6 commit 96e5f7f

File tree

2 files changed

+30
-41
lines changed

2 files changed

+30
-41
lines changed

content/3_Silver/Binary_Search.problems.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@
126126
"isStarred": false,
127127
"tags": ["Binary Search"],
128128
"solutionMetadata": {
129-
"kind": "internal"
129+
"kind": "internal",
130+
"hasHints": true
130131
}
131132
},
132133
{

solutions/silver/cses-1620.mdx

+28-40
Original file line numberDiff line numberDiff line change
@@ -39,68 +39,55 @@ that it's optimal for every machine to work simultaneously. Then, in $ans$ time,
3939
machine $i$ can create $\lfloor \frac{ans}{k_i} \rfloor$ products.
4040

4141
Overall, the $n$ machines can create
42-
‎‎$\sum_{i=1}^{n} \lfloor \frac{ans}{k_i} \rfloor$ products. If this sum
42+
$\sum_{i=1}^{n} \lfloor \frac{ans}{k_i} \rfloor$ products. If this sum
4343
$\geq t$, then $ans$ is valid.
4444

4545
## Implementation
4646

47-
**Time Complexity:** $\mathcal{O}(n \log t)$, where $t$ is the largest time we need to consider.
47+
**Time Complexity:** $\mathcal{O}(N \log T)$, where $T$ is the largest time we need to consider.
4848

4949
<LanguageSection>
5050
<CPPSection>
5151

5252
```cpp
53-
#include <bits/stdc++.h>
54-
using namespace std;
55-
using ll = long long;
56-
using vi = vector<int>;
57-
#define pb push_back
58-
#define rsz resize
59-
#define all(x) begin(x), end(x)
60-
#define sz(x) (int)(x).size()
61-
using pi = pair<int, int>;
62-
#define f first
63-
#define s second
64-
#define mp make_pair
65-
void setIO(string name = "") { // name is nonempty for USACO file I/O
66-
ios_base::sync_with_stdio(0);
67-
cin.tie(0); // see Fast Input & Output
68-
if (sz(name)) {
69-
freopen((name + ".in").c_str(), "r", stdin); // see Input & Output
70-
freopen((name + ".out").c_str(), "w", stdout);
71-
}
72-
}
53+
#include <climits>
54+
#include <iostream>
55+
#include <vector>
56+
57+
using std::vector;
7358

7459
int main() {
75-
setIO();
7660
int n;
77-
ll t, mn = INT_MAX;
78-
cin >> n >> t;
79-
vector<ll> k(n);
80-
for (int i = 0; i < n; i++) {
81-
cin >> k[i];
82-
mn = min(mn, k[i]);
61+
long long t;
62+
std::cin >> n >> t;
63+
vector<int> k(n);
64+
65+
int mn = INT_MAX;
66+
for (int &x : k) {
67+
std::cin >> x;
68+
mn = std::min(mn, x);
8369
}
84-
ll lo = 0;
85-
ll hi = mn * t;
86-
ll ans = 0;
70+
71+
long long lo = 0;
72+
long long hi = mn * t;
73+
long long res = 0;
8774
while (lo <= hi) {
88-
ll mid = (lo + hi) / 2;
89-
ll sum = 0;
75+
long long mid = (lo + hi) / 2;
76+
long long sum = 0;
9077
for (int i = 0; i < n; i++) {
9178
sum += (mid / k[i]);
92-
if (sum >= t) { // deal with overflow
93-
break;
94-
}
79+
if (sum >= t) { break; }
9580
}
81+
9682
if (sum >= t) {
97-
ans = mid;
83+
res = mid;
9884
hi = mid - 1;
9985
} else {
10086
lo = mid + 1;
10187
}
10288
}
103-
cout << ans << "\n";
89+
90+
std::cout << res << std::endl;
10491
}
10592
```
10693
@@ -157,7 +144,7 @@ _, goal = map(int, input().split())
157144
machines = list(map(int, input().split()))
158145

159146
lo = 0
160-
hi = int(1e18)
147+
hi = 10**18
161148
ans = 0
162149
while lo <= hi:
163150
mid = (lo + hi) // 2
@@ -171,6 +158,7 @@ while lo <= hi:
171158
hi = mid - 1
172159
else:
173160
lo = mid + 1
161+
174162
print(ans)
175163
```
176164

0 commit comments

Comments
 (0)