Advertisement
Guest User

Untitled

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