From a101940e6a44b797acd441f1cc3039cccfcbe1ad Mon Sep 17 00:00:00 2001 From: Segcolt <9hmbzr275@mozmail.com> Date: Wed, 2 Oct 2024 12:18:10 -0300 Subject: [PATCH] Quick modification before having to leave --- .../Cards Distribution.cpp | 83 ++++++++++++++----- 1 file changed, 60 insertions(+), 23 deletions(-) diff --git a/Data Structures and Libraries/Cards Distribution.cpp b/Data Structures and Libraries/Cards Distribution.cpp index f5f8fc2..59923c2 100644 --- a/Data Structures and Libraries/Cards Distribution.cpp +++ b/Data Structures and Libraries/Cards Distribution.cpp @@ -69,6 +69,11 @@ auto operator>>(istream &is, vector> &vec)->istream& { return is; } +struct player { + int total; + list cards; +}; + int main() { ios::sync_with_stdio(false); @@ -96,33 +101,65 @@ int main() total += cards.back(); } - size_t i = 0; - size_t j = 0; - int cmax = 0; - int now = 0; - while (j < cards.size()) { - if (total - now < now) { - now -= cards[i]; - i++; - continue; + V players(p); + int lim = cards.size() / p; + int count = 0; + size_t now = 0; + for (size_t i = 0; i < lim * p;) { + for (size_t j = 0; j < lim; j++, i++) { + players[now].cards.push_back(cards[i]); + players[now].total += cards[i]; + count++; } - now += cards[j]; - j++; - rmax(cmax, now); + now++; } - int amax = 0; - now = 0; - int num = 0; - for (auto i : cards) { - if (now + i > cmax) { - now = i; - num = 1; - } else { - now += i; - num++; + while (count < cards.size()) { + players[now - 1].cards.push_back(cards[count]); + players[now - 1].total += cards[count]; + count++; + } + + size_t i = 1; + while (i < p) { + int act = max(players[i].total, players[i - 1].total); + if (max(players[i - 1].total + players[i].cards.back(), players[i].total - players[i].cards.back()) <= act || + max(players[i].total + players[i - 1].cards.front(), players[i - 1].total - players[i - 1].cards.front()) < act) { + + if (players[i].total + players[i - 1].cards.back() < players[i - 1].total + players[i].cards.front()) { + players[i].total += players[i - 1].cards.back(); + players[i - 1].total -= players[i - 1].cards.back(); + players[i].cards.push_front(players[i - 1].cards.back()); + players[i].cards.pop_back(); + } else { + players[i - 1].total += players[i].cards.front(); + players[i].total -= players[i].cards.front(); + players[i - 1].cards.push_front(players[i].cards.front()); + players[i - 1].cards.pop_front(); + } + continue; } - rmax(amax, num); + + i++; + } + + int cmax = 0; + for (auto &i : players) { + rmax(cmax, i.total); + } + + int amax = 1; + int no = 1; + int val = cards[0]; + for (size_t i = 1; i < cards.size(); i++) { + if (val + cards[i] > cmax) { + val = cards[i]; + no = 1; + } else { + val += cards[i]; + no++; + } + rmax(amax, no); } cout << amax << ' ' << cmax << '\n';