Advertisement
7oSkaaa

G. Boxes

Jul 29th, 2022
1,101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.90 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define cin_2d(vec, n, m) for(int i = 0; i < n; i++) for(int j = 0; j < m && cin >> vec[i][j]; j++);
  6. #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++);
  7. #define fixed(n) fixed << setprecision(n)
  8. #define ceil(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  9. #define fill(vec, value) memset(vec, value, sizeof(vec));
  10. #define mul_mod(a, b, m) (((a % m) * (b % m)) % m)
  11. #define add_mod(a, b, m) (((a % m) + (b % m)) % m)
  12. #define all(vec) vec.begin(), vec.end()
  13. #define rall(vec) vec.rbegin(), vec.rend()
  14. #define sz(x) int(x.size())
  15. #define debug(x) cout << #x << ": " << (x) << "\n";
  16. #define fi first
  17. #define se second
  18. #define ll long long
  19. #define ull unsigned long long
  20. #define Mod  1'000'000'007
  21. #define OO 2'000'000'000
  22. #define EPS 1e-9
  23. #define PI acos(-1)
  24. template < typename T = int > using Pair = pair < T, T >;
  25. vector < string > RET = {"NO", "YES"};
  26.  
  27. template < typename T = int > istream& operator >> (istream &in, vector < T > &v) {
  28.     for (auto &x : v) in >> x;
  29.     return in;
  30. }
  31.  
  32. template < typename T = int > ostream& operator << (ostream &out, const vector < T > &v) {
  33.     for (const T &x : v) out << x << ' ';
  34.     return out;
  35. }
  36.  
  37. void Solve(){
  38.     int n;
  39.     cin >> n;
  40.     // we need to store the largest number that Gemmy took, and same thing for Nasr
  41.     // the steal turn will be the swap of these two numbers because they play optimal
  42.     ll a[n];
  43.     for(int i = 0; i < n; i++)
  44.         cin >> a[i];
  45.     ll Nasr = 0, Gemmy = 0, Max_Nasr = 0, Max_Gemmy = 0;
  46.     int l = 0, r = n - 1, turn = true;
  47.     // turn is true when Gemmy is playing, false when Nasr is playing
  48.     while(l < r){
  49.         if(turn){
  50.             // Gemmy will be on the left side and Nasr will be on the right side
  51.             Gemmy += a[l], Nasr += a[r];
  52.             Max_Gemmy = max(Max_Gemmy, a[l]);
  53.             Max_Nasr = max(Max_Nasr, a[r]);
  54.         }else {
  55.             // Nasr will be on the left side and Gemmy will be on the right side
  56.             Gemmy += a[r], Nasr += a[l];
  57.             Max_Gemmy = max(Max_Gemmy, a[r]);
  58.             Max_Nasr = max(Max_Nasr, a[l]);
  59.         }
  60.         // swap turn
  61.         turn = !turn;
  62.         l++, r--;
  63.     }
  64.     // Gemmy always plays first
  65.     if(l == r)
  66.         Gemmy += a[l], Max_Gemmy = max(Max_Gemmy, a[l]);
  67.     // add max_element from nasr and give nasr the max_element of him
  68.     Gemmy += Max_Nasr - Max_Gemmy;
  69.     // add max_element from gemmy and give gemmy the max_element of him
  70.     Nasr += Max_Gemmy - Max_Nasr;
  71.     if(Gemmy > Nasr)
  72.         cout << "Gemmy" << "\n";
  73.     else if(Nasr > Gemmy)
  74.         cout << "Nasr" << "\n";
  75.     else
  76.         cout << "Tie" << "\n";
  77. }
  78.  
  79. int main(){
  80.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  81.     int t = 1;
  82.     //cin >> t;
  83.     while(t--)
  84.         Solve();
  85.     return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement