Advertisement
Josif_tepe

Untitled

Mar 13th, 2023
807
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <map>
  3. #include <cmath>
  4. #include <set>
  5. #include <vector>
  6. #include <queue>
  7. #include <algorithm>
  8. using namespace std;
  9. typedef long long ll;
  10. int main() {
  11.     ios_base::sync_with_stdio(false);
  12.     vector<ll> v(3);
  13.     cin >> v[0] >> v[1] >> v[2];
  14.     ll x, n;
  15.     cin >> x >> n;
  16.     sort(v.begin(), v.end());
  17.    
  18.     ll diff = v[1] - v[0];
  19.     ll a_add = (diff + x - 1) / x;
  20.     if(n >= a_add) {
  21.         n -= a_add;
  22.         v[0] += a_add * x;
  23.     }
  24.     else {
  25.         v[0] += n * x;
  26.         sort(v.begin(), v.end());
  27.         cout << v[0] << " " << v[1] << " " << v[2] << endl;
  28.         return 0;
  29.     }
  30.     ll b_add = (v[2] - v[1]) / x + (v[2] - v[0]) / x;
  31.     if(n >= b_add) {
  32.         n -= b_add;
  33.         v[1] += ((v[2] - v[1]) / x) * x;
  34.         v[0] += ((v[2] - v[0]) / x) * x;
  35.     }
  36.     else {
  37.         v[0] += (n / 2) * x;
  38.         v[1] += ((n + 1) / 2) * x;
  39.         sort(v.begin(), v.end());
  40.         cout << v[0] << " " << v[1] << " " << v[2] << endl;
  41.         return 0;
  42.     }
  43.     ll c_add = n / 3;
  44.     v[0] += c_add * x;
  45.     v[1] += c_add * x;
  46.     v[2] += c_add * x;
  47.    
  48.     if(n % 3 == 2) {
  49.         v[0] += x;
  50.         v[1] += x;
  51.     }
  52.     else if(n % 3 == 1) {
  53.         if(v[0] <= v[1]){
  54.             v[0] += x;
  55.         }
  56.         else {
  57.             v[1] += x;
  58.         }
  59.     }
  60.     sort(v.begin(), v.end());
  61.     cout << v[0] << " " << v[1] << " " << v[2] << endl;
  62.    
  63.     return 0;
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement