Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <cmath>
- #include <set>
- #include <vector>
- #include <queue>
- #include <algorithm>
- using namespace std;
- typedef long long ll;
- int main() {
- ios_base::sync_with_stdio(false);
- vector<ll> v(3);
- cin >> v[0] >> v[1] >> v[2];
- ll x, n;
- 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());
- cout << v[0] << " " << v[1] << " " << v[2] << endl;
- 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());
- cout << v[0] << " " << v[1] << " " << v[2] << endl;
- 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());
- cout << v[0] << " " << v[1] << " " << v[2] << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement