Advertisement
Korotkodul

mzp_N2

Nov 3rd, 2022 (edited)
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <string>
  7. #include <stack>
  8. #include <set>
  9. #include <map>
  10. #define pii pair <int, int>
  11. #define pb(x) push_back(x)
  12. using namespace std;
  13. using ll = long long;
  14. using ld = long double;
  15. using db = double;
  16. void cv(vector <int> &v) {
  17.     for (auto x : v) cout << x << ' ';
  18.     cout << "\n";
  19. }
  20.  
  21. void cvl(vector <ll> &v) {
  22.     for (auto x : v) cout << x << ' ';
  23.     cout << "\n";
  24. }
  25.  
  26.  
  27. void cvv(vector <vector <int> > &v) {
  28.     for (auto x : v) cv(x);
  29.     cout << "\n";
  30. }
  31.  
  32. void cvb(vector <bool> v) {
  33.     for (bool x : v) cout << x << ' ';
  34.     cout << "\n";
  35. }
  36.  
  37. void cvs(vector <string>  v) {
  38.     for (auto a : v) {
  39.         cout << a << "\n";
  40.     }
  41. }
  42.  
  43. void cvp(vector <pii> a) {
  44.     for (auto p : a) {
  45.         cout << p.first << ' ' << p.second << "\n";
  46.     }
  47.     cout << "\n";
  48. }
  49.  
  50. bool cmp(vector <int> a, vector <int> b) {
  51.     return a[0] > b[0];
  52. }
  53.  
  54. vector <int> ans = {-1, -1, -1};
  55. int A, B, C, n;
  56.  
  57. bool ok(int x) {
  58.     int y, z, a, b, c;
  59.     a = A + x;
  60.     if (a % 2 == 1) {
  61.         return 0;
  62.     }
  63.     b = a / 2;
  64.     y = b - B;
  65.     c = b;
  66.     z = c - C;
  67.     bool r = x + y + z <= n && y >= 0 && z >= 0;
  68.     if (r) {
  69.         ans[0] = x;
  70.         ans[1] = y;
  71.         ans[2] = z;
  72.     }
  73.     return r;
  74. }
  75.  
  76. int main() {
  77.     ios::sync_with_stdio(0);
  78.     cin.tie(0);
  79.     cout.tie(0);
  80.  
  81.     cin >> A >> B >> C >> n;
  82.     int l = 0 + A % 2, r = n + n % 2 + A % 2, m;
  83.     while (l + 1 < r) {
  84.         m = (l + r) / 2;
  85.         if (ok(m)) {
  86.             l = m;
  87.         } else {
  88.             r = m;
  89.         }
  90.     }
  91.     if (ans[0] == -1) {
  92.         cout << 0;
  93.         exit(0);
  94.     }
  95.     for (int i: ans) {
  96.         cout << i << "\n";
  97.     }
  98. }
  99.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement