From 92daea9371e9375403b792607d371856939718bf Mon Sep 17 00:00:00 2001 From: Segcolt <9hmbzr275@mozmail.com> Date: Tue, 1 Oct 2024 21:24:06 -0300 Subject: [PATCH] Trying to do one problem that I say someone else do It might be fun. --- .gitignore | 1 + .../Cards Distribution.cpp | 129 ++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 Data Structures and Libraries/Cards Distribution.cpp diff --git a/.gitignore b/.gitignore index e257658..48eea07 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ *.out *.app +*.testcases diff --git a/Data Structures and Libraries/Cards Distribution.cpp b/Data Structures and Libraries/Cards Distribution.cpp new file mode 100644 index 0000000..f5f8fc2 --- /dev/null +++ b/Data Structures and Libraries/Cards Distribution.cpp @@ -0,0 +1,129 @@ +/* Problem URL: https://judge.beecrowd.com/en/problems/view/2821 */ + +#include + +using namespace std; + +#define V vector + +#define rmin(a, b) a = min(a, b) +#define rmax(a, b) a = max(a, b) + +#define rep(i, lim) for (size_t i = 0; i < (lim); i++) +#define nrep(i, s, lim) for (size_t i = s; i < (lim); i++) + +#define repv(i, v) for (auto &i : (v)) +#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; } +#define sortv(v) sort(v.begin(), v.end()) +#define all(v) (v).begin(), (v).end() + +using vi = vector; +using vvi = vector; +using vvvi = vector; +using vvvvi = vector; + +using ll = long long; + +using vl = vector; +using vvl = vector; +using vvvl = vector; +using vvvvl = vector; + +template +auto operator<<(ostream &os, const vector &vec)->ostream& { + os << vec[0]; + for (size_t i = 1; i < vec.size(); i++) { + os << ' ' << vec[i]; + } + os << '\n'; + return os; +} + +template +auto operator>>(istream &is, vector &vec)->istream& { + for (auto &i : vec) { + is >> i; + } + return is; +} + +template +auto operator<<(ostream &os, const vector> &vec)->ostream& { + for (auto &i : vec) { + os << i[0]; + for (size_t j = 1; j < i.size(); j++) { + os << ' ' << i[j]; + } + os << '\n'; + } + return os; +} + +template +auto operator>>(istream &is, vector> &vec)->istream& { + for (auto &i : vec) { + for (auto &j : i) { + is >> j; + } + } + return is; +} + +int main() +{ + ios::sync_with_stdio(false); + cin.tie(nullptr); + + int n, p; + cin >> n >> p; + + map act; + act["A"] = 1; + act["J"] = 11; + act["Q"] = 12; + act["K"] = 13; + for (size_t i = 2; i <= 10; i++) { + act[to_string(i)] = i; + } + + vi cards; + ll total = 0; + + while (n--) { + string a; + cin >> a; + cards.push_back(act[a]); + 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; + } + now += cards[j]; + j++; + rmax(cmax, 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++; + } + rmax(amax, num); + } + + cout << amax << ' ' << cmax << '\n'; +}