Advertisement
savrasov

Untitled

Apr 10th, 2017
542
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. int a[200000], n, m, ar[20], b = 0;
  7.  
  8. bool ch(int i)
  9. {
  10.     return (a[i] == n + 1 || (b && a[i] == n));
  11. }
  12.  
  13. int main()
  14. {
  15.     cin >> n >> m;
  16.     for (int i = 0; i < m; i++) \
  17.     {
  18.         cin >> ar[i];
  19.         if (!ar[i]) i--, m--, b = 1;
  20.     }
  21.     sort(ar, ar + m);
  22.     a[0] = 1;
  23.     for (int i = 1; i < 150000; i++)
  24.         for (int j = 0; j < m; j++)
  25.             if (i - ar[j] >= 0 && a[i - ar[j]])
  26.             {
  27.                 if (a[i] == 0) a[i] = a[i - ar[j]] + 1;
  28.                 else a[i] = min(a[i], a[i - ar[j]] + 1);
  29.                 if (a[i] > n + 1) a[i] = 0;
  30.             }
  31.     int bol = 0;
  32.     for (int i = 1; i < 150000; i++)
  33.         if (ch(i) && !(i % 9) && ((a[i])% 2 || (m == 1 && ar[m - 1] == 9))) bol = 1;
  34.     if (bol) cout << "Gena";
  35.     else cout << "Petya";
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement