Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define cin_2d(vec, n, m) for(int i = 0; i < n; i++) for(int j = 0; j < m && cin >> vec[i][j]; j++);
- #define cout_2d(vec, n, m) for(int i = 0; i < n; i++, cout << "\n") for(int j = 0; j < m && cout << vec[i][j] << " "; j++);
- #define fixed(n) fixed << setprecision(n)
- #define ceil(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
- #define fill(vec, value) memset(vec, value, sizeof(vec));
- #define mul_mod(a, b, m) (((a % m) * (b % m)) % m)
- #define add_mod(a, b, m) (((a % m) + (b % m)) % m)
- #define all(vec) vec.begin(), vec.end()
- #define rall(vec) vec.rbegin(), vec.rend()
- #define sz(x) int(x.size())
- #define debug(x) cout << #x << ": " << (x) << "\n";
- #define fi first
- #define se second
- #define ll long long
- #define ull unsigned long long
- #define Mod 1'000'000'007
- #define OO 2'000'000'000
- #define EPS 1e-9
- #define PI acos(-1)
- template < typename T = int > using Pair = pair < T, T >;
- vector < string > RET = {"NO", "YES"};
- template < typename T = int > istream& operator >> (istream &in, vector < T > &v) {
- for (auto &x : v) in >> x;
- return in;
- }
- template < typename T = int > ostream& operator << (ostream &out, const vector < T > &v) {
- for (const T &x : v) out << x << ' ';
- return out;
- }
- void Solve(){
- int n;
- cin >> n;
- // we need to store the largest number that Gemmy took, and same thing for Nasr
- // the steal turn will be the swap of these two numbers because they play optimal
- ll a[n];
- for(int i = 0; i < n; i++)
- cin >> a[i];
- ll Nasr = 0, Gemmy = 0, Max_Nasr = 0, Max_Gemmy = 0;
- int l = 0, r = n - 1, turn = true;
- // turn is true when Gemmy is playing, false when Nasr is playing
- while(l < r){
- if(turn){
- // Gemmy will be on the left side and Nasr will be on the right side
- Gemmy += a[l], Nasr += a[r];
- Max_Gemmy = max(Max_Gemmy, a[l]);
- Max_Nasr = max(Max_Nasr, a[r]);
- }else {
- // Nasr will be on the left side and Gemmy will be on the right side
- Gemmy += a[r], Nasr += a[l];
- Max_Gemmy = max(Max_Gemmy, a[r]);
- Max_Nasr = max(Max_Nasr, a[l]);
- }
- // swap turn
- turn = !turn;
- l++, r--;
- }
- // Gemmy always plays first
- if(l == r)
- Gemmy += a[l], Max_Gemmy = max(Max_Gemmy, a[l]);
- // add max_element from nasr and give nasr the max_element of him
- Gemmy += Max_Nasr - Max_Gemmy;
- // add max_element from gemmy and give gemmy the max_element of him
- Nasr += Max_Gemmy - Max_Nasr;
- if(Gemmy > Nasr)
- cout << "Gemmy" << "\n";
- else if(Nasr > Gemmy)
- cout << "Nasr" << "\n";
- else
- cout << "Tie" << "\n";
- }
- int main(){
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- int t = 1;
- //cin >> t;
- while(t--)
- Solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement