From d858d4e65a520d84a35a03f351d5c0656aeaacb4 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sat, 25 Jun 2022 20:23:57 +0800 Subject: [PATCH] C - Robot Takahashi https://atcoder.jp/contests/abc257/submissions/32722712 --- AtCoder/ABC257/C/C.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 AtCoder/ABC257/C/C.cpp diff --git a/AtCoder/ABC257/C/C.cpp b/AtCoder/ABC257/C/C.cpp new file mode 100644 index 00000000..18513d05 --- /dev/null +++ b/AtCoder/ABC257/C/C.cpp @@ -0,0 +1,50 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 2e5 + 5; + +int n, w[N], a[N], x[N], y[N], ans; +std::string s; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> s; + + s = ' ' + s; + + for (int i = 1; i <= n; i++) { + cin >> w[i]; + + a[i] = w[i]; + } + + std::sort(a + 1, a + 1 + n); + + for (int i = 1; i <= n; i++) { + w[i] = std::lower_bound(a + 1, a + 1 + n, w[i]) - a; + } + + for (int i = 1; i <= n; i++) { + (s[i] == '0' ? x : y)[w[i]]++; + } + + for (int i = 1; i <= n; i++) { + x[i] += x[i - 1]; + y[i] += y[i - 1]; + } + + for (int i = 1; i <= n + 1; i++) { + ans = std::max(ans, x[i - 1] + y[n] - y[i - 1]); + } + + cout << ans << endl; + + return 0; +}