Dang_Quan_10_Tin

BTICK HSGTPHCM L9 2016-2017

Jan 14th, 2022 (edited)
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #define task "BTICk"
  2.  
  3. #include <iostream>
  4. #include <cstdio>
  5.  
  6. using namespace std;
  7.  
  8. using ll = long long;
  9.  
  10. ll n, k, p1, p2;
  11.  
  12. void Read()
  13. {
  14.     cin >> n >> k >> p1 >> p2;
  15. }
  16.  
  17. void Solve()
  18. {
  19.     if (p1 >= p2)
  20.         cout << (n + k - 1) / k * p2; // mua ceil(n / k) tệp
  21.     else if (p1 * k <= p2)
  22.         cout << n * p1; // Mua cả n vé lẻ
  23.     else
  24.     {
  25.         ll ans = n / k * p2; // Mua n / k tệp
  26.         ll x = n % k;        // Phần dư
  27.  
  28.         if (p1 * x >= p2)
  29.             ans += p2;
  30.         else
  31.             ans += p1 * x;
  32.  
  33.         cout << ans;
  34.     }
  35. }
  36.  
  37. int32_t main()
  38. {
  39.     ios::sync_with_stdio(0);
  40.     cin.tie(0);
  41.     cout.tie(0);
  42.     if (fopen(task ".INP", "r"))
  43.     {
  44.         freopen(task ".INP", "r", stdin);
  45.         freopen(task ".OUT", "w", stdout);
  46.     }
  47.  
  48.     Read();
  49.     Solve();
  50. }
  51.  
Add Comment
Please, Sign In to add comment