aboutsummaryrefslogtreecommitdiff
path: root/42
diff options
context:
space:
mode:
Diffstat (limited to '42')
-rw-r--r--42/apple.cc40
1 files changed, 40 insertions, 0 deletions
diff --git a/42/apple.cc b/42/apple.cc
new file mode 100644
index 0000000..b9cce28
--- /dev/null
+++ b/42/apple.cc
@@ -0,0 +1,40 @@
+#include <bits/stdc++.h>
+#include <cstdint>
+using namespace std;
+
+uint64_t n, k, m;
+
+bool can_live(uint64_t robot_num) {
+ uint64_t total_apple = n;
+ for (int day = 1; day <= m; ++day) {
+ uint64_t rot = (total_apple * k + 99) / 100;
+ total_apple -= rot;
+ if (total_apple < robot_num) {
+ return false;
+ }
+ total_apple -= robot_num;
+ }
+ return true;
+}
+
+int main() {
+ ios::sync_with_stdio(false);
+ cin.tie(nullptr);
+ cin >> n >> k >> m;
+
+ uint64_t left = 0;
+ uint64_t right = n / m;
+ uint64_t res = 0;
+
+ while (left <= right) {
+ uint64_t mid = left + (right - left) / 2;
+ if (can_live(mid)) {
+ res = mid;
+ left = mid + 1;
+ } else {
+ right = mid - 1;
+ }
+ }
+ cout << res << "\n";
+ return 0;
+}