# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
395133 |
2021-04-27T21:18:37 Z |
kaplanbar |
Roses (BOI20_roses) |
C++14 |
|
1 ms |
204 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
ll n;
ll a, b, c, d;
cin >> n >> a >> b >> c >> d;
ll lcm = (a * c) / __gcd(a, c);
ll take = (n / lcm) * lcm;
ll best = min((take / a) * b, (take / c) * d);
n -= take;
ll ans = 1e18;
if(a >= c) {
assert(n / a <= 1e7);
for(int i = 0; i <= (n + a - 1) / a; i++) {
ll other = max(0ll, n - i * a + c - 1) / c;
ans = min(ans, i * b + other * d);
}
}
else {
assert(n / c <= 1e7);
for(int i = 0; i <= (n + c - 1) / c; i++) {
ll other = max(0ll, n - i * c + a - 1) / a;
ans = min(ans, i * d + other * b);
}
}
cout << ans + best;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |