0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 13:56:26 +00:00

C - Robot Takahashi

https://atcoder.jp/contests/abc257/submissions/32722712
This commit is contained in:
Baoshuo Ren 2022-06-25 20:23:57 +08:00
parent a237f25d9a
commit d858d4e65a
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

50
AtCoder/ABC257/C/C.cpp Normal file
View File

@ -0,0 +1,50 @@
#include <iostream>
#include <algorithm>
#include <string>
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;
}