-
Notifications
You must be signed in to change notification settings - Fork 0
/
task_1607.cpp
28 lines (22 loc) · 884 Bytes
/
task_1607.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
int main() {
std::ios::sync_with_stdio(false);
int offer_petr, step_petr, offer_driver, step_driver;
std::cin >> offer_petr >> step_petr >> offer_driver >> step_driver;
// while(offer_petr < offer_driver) {
// offer_petr = std::min(offer_petr + step_petr, offer_driver);
// offer_driver -= step_driver;
// }
// std::cout << offer_petr;
// offer_petr + n_steps * step_petr >= offer_driver - n_steps * step_driver
// n_steps (step_petr + step_driver) >= offer_driver - offer_petr
int n_steps = (offer_driver - offer_petr + step_petr + step_driver - 1) / (step_petr + step_driver);
int result;
if (n_steps <= 0) {
result = offer_petr;
} else {
result = std::min(offer_petr + n_steps * step_petr, offer_driver - (n_steps - 1) * step_driver);
}
std::cout << result;
return 0;
}