IMohammedNasr

Untitled

Dec 10th, 2021
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5. void ez()
  6. {
  7. ios_base::sync_with_stdio(false), cin.tie(nullptr), std::cout.tie(nullptr);
  8. #ifndef ONLINE_JUDGE
  9. freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  10. #endif
  11. }
  12.  
  13. bool comp(ll &a, ll &b)
  14. {
  15. return a > b;
  16. }
  17.  
  18. void solve()
  19. {
  20. ll n, cnt1 = 0, cnt2 = 0;
  21. cin >> n;
  22. vector<ll> v(n);
  23. for (auto &i : v)
  24. cin >> i;
  25.  
  26. ll f = 0, l = n - 1;
  27.  
  28. map<int, string> m;
  29.  
  30. while (f < l)
  31. {
  32.  
  33. if (v[l] > v[f])
  34. {
  35. cnt1++;
  36. v[l] -= v[f];
  37. m[l] = "Bob";
  38. v[f] = 0;
  39. f++;
  40. }
  41. else if (v[f] > v[l])
  42. {
  43. cnt2++;
  44. v[f] -= v[l];
  45. m[f] = "Alice";
  46. v[l] = 0;
  47. l--;
  48. }
  49. else
  50. {
  51. cnt1++, cnt2++;
  52. v[f] = v[l] = 0;
  53. f++, l--;
  54. }
  55. }
  56. if (v[f])
  57. {
  58. (m[f] == "Bob" ? cnt2++ : cnt1++);
  59. }
  60. std::cout << cnt1 << " " << cnt2 << endl;
  61. }
  62.  
  63. int main()
  64. {
  65. ez();
  66. int t = 1;
  67. // cin >> t;
  68. while (t--)
  69. solve();
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment