Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4.  
  5. ll n, k, a, b, c, d;
  6.  
  7. bool check(ll pos, int guy) {
  8.     ll sum1 = 0, sum2 = 0;
  9.     int state = guy;
  10.     for (ll i = pos; i <= n; i += k) {
  11.         if (!state) {
  12.             if (i >= a && i <= b)
  13.                 ++sum2;
  14.             else
  15.                 ++sum1;
  16.         }
  17.         else {
  18.             if (i >= c && i <= d)
  19.                 ++sum1;
  20.             else
  21.                 ++sum2;
  22.         }
  23.         state ^= 1;
  24.     }
  25.     // cout << sum1 << " " << sum2 << endl;
  26.     return sum1 == sum2;
  27. }
  28.  
  29. int main() {
  30.     //0 - d, 1 - m
  31.     cin >> n >> k >> a >> b >> c >> d;
  32.     for (int i = 1; i <= k; ++i) {
  33.         if (check(i, 1)) {
  34.             cout << i << '\n' << "Mitya";
  35.             return 0;
  36.         }
  37.         if (check(i, 0)) {
  38.             cout << i << '\n' << "Dima";
  39.             return 0;
  40.         }
  41.     }
  42.     cout << -1;
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement