Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int a[200000], n, m, ar[20], b = 0;
- bool ch(int i)
- {
- return (a[i] == n + 1 || (b && a[i] == n));
- }
- int main()
- {
- cin >> n >> m;
- for (int i = 0; i < m; i++) \
- {
- cin >> ar[i];
- if (!ar[i]) i--, m--, b = 1;
- }
- sort(ar, ar + m);
- a[0] = 1;
- for (int i = 1; i < 150000; i++)
- for (int j = 0; j < m; j++)
- if (i - ar[j] >= 0 && a[i - ar[j]])
- {
- if (a[i] == 0) a[i] = a[i - ar[j]] + 1;
- else a[i] = min(a[i], a[i - ar[j]] + 1);
- if (a[i] > n + 1) a[i] = 0;
- }
- int bol = 0;
- for (int i = 1; i < 150000; i++)
- if (ch(i) && !(i % 9) && ((a[i])% 2 || (m == 1 && ar[m - 1] == 9))) bol = 1;
- if (bol) cout << "Gena";
- else cout << "Petya";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement