Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- void ez()
- {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), std::cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- bool comp(ll &a, ll &b)
- {
- return a > b;
- }
- void solve()
- {
- ll n, cnt1 = 0, cnt2 = 0;
- cin >> n;
- vector<ll> v(n);
- for (auto &i : v)
- cin >> i;
- ll f = 0, l = n - 1;
- map<int, string> m;
- while (f < l)
- {
- if (v[l] > v[f])
- {
- cnt1++;
- v[l] -= v[f];
- m[l] = "Bob";
- v[f] = 0;
- f++;
- }
- else if (v[f] > v[l])
- {
- cnt2++;
- v[f] -= v[l];
- m[f] = "Alice";
- v[l] = 0;
- l--;
- }
- else
- {
- cnt1++, cnt2++;
- v[f] = v[l] = 0;
- f++, l--;
- }
- }
- if (v[f])
- {
- (m[f] == "Bob" ? cnt2++ : cnt1++);
- }
- std::cout << cnt1 << " " << cnt2 << endl;
- }
- int main()
- {
- ez();
- int t = 1;
- // cin >> t;
- while (t--)
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment