IMohammedNasr

C. Alice, Bob and Chocolate

Dec 10th, 2021
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 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), 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, AliceSum = 0, BobSum = 0, 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. while (f < l)
  29. {
  30. if (v[l] > v[f])
  31. {
  32. cnt1++;
  33. v[l] -= v[f];
  34. AliceSum += v[f];
  35. v[f] = 0;
  36. f++;
  37. }
  38. else if (v[f] > v[l])
  39. {
  40. cnt2++;
  41. v[f] -= v[l];
  42. BobSum += v[l];
  43. v[l] = 0;
  44. l--;
  45. }
  46. else
  47. {
  48. cnt1++, cnt2++;
  49. AliceSum += v[f];
  50. BobSum += v[l];
  51. v[f] = v[l] = 0;
  52. f++, l--;
  53. }
  54. }
  55. if ((v[l] or v[f]))
  56. {
  57. if (n % 2)
  58. (AliceSum >= BobSum ? cnt1++ : cnt2++);
  59. else
  60. {
  61. (v[f] ? cnt1++ : cnt2++);
  62. }
  63. }
  64. cout << cnt1 << " " << cnt2 << endl;
  65. }
  66.  
  67. int main()
  68. {
  69. ez();
  70. int t = 1;
  71. // cin >> t;
  72. while (t--)
  73. solve();
  74. return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment