Untitled

mail@pastecode.io avatar
unknown
c_cpp
23 days ago
1.3 kB
1
Indexable
Never
#include <iostream>
using namespace std;
typedef long long ll;
int main()
{
    vector<ll> v(3);
    ll x, n;
    cin >> v[0] >> v[1] >> v[2];
    cin >> x >> n;
    sort(v.begin(), v.end());
    
    ll diff = v[1] - v[0];
    ll a_add = (diff + x - 1) / x;
    if(n >= a_add) {
        n -= a_add;
        v[0] += a_add * x;
    }
    else {
        v[0] += n * x;
        sort(v.begin(), v.end());
        for(int i = 0; i < 3; i++) {
            cout << v[i] << " ";
        }
        return 0;
    }
    
    ll b_add = (v[2] - v[1]) / x + (v[2] - v[0]) / x;
    if(n >= b_add) {
        n -= b_add;
        v[1] += ((v[2] - v[1]) / x) * x;
        v[0] += ((v[2] - v[0]) / x) * x;
    }
    else {
        v[0] += (n / 2) * x;
        v[1] += ((n + 1) / 2) * x;
        sort(v.begin(), v.end());
        for(int i = 0; i < 3; i++) {
            cout << v[i] << " ";
        }
        return 0;
    }
    ll c_add = n / 3;
    v[0] += c_add * x;
    v[1] += c_add * x;
    v[2] += c_add * x;
    
    if(n % 3 == 2) {
        v[0] += x;
        v[1] += x;
    }
    else if(n % 3 == 1) {
        if(v[0] <= v[1]) {
            v[0] += x;
        }
        else {
            v[1] += x;
        }
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < 3; i++) {
        cout << v[i] << " ";
    }
    return 0;
}


Leave a Comment