QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#621452 | #8783. Cherry Picking | ucup-team2526 | WA | 1ms | 5612kb | C++20 | 2.5kb | 2024-10-08 14:39:17 | 2024-10-08 14:39:35 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define dbg(x...) \
do { \
cout << #x << " -> "; \
err(x); \
} while (0)
void err() {
cout<<endl<<endl;
}
template<class T, class... Ts>
void err(T arg, Ts ... args) {
cout<<fixed<<setprecision(10)<<arg<< ' ';
err(args...);
}
const int maxn = 1e5 + 5;
struct BIT {
#define lowbit(x) (x&(-x))
int tr[maxn << 2];
void add(int u,int v) {
while (u <= maxn) {
tr[u] += v;
u += lowbit(u);
}
}
int get(int u) {
int res = 0;
while (u) {
res += tr[u];
u -= lowbit(u);
}
return res;
}
}bit;
void solve(){
int n,k;cin >> n >> k;
vector<int> a(n + 5);
for (int i = 1;i <= n;i++) cin >> a[i];
string res;cin >> res;
int l = -1,r = -1;
for (int i = 1;i <= n;i++) {
if (res[i - 1] == '1') {
bit.add(a[i],1);
l = i,r = i;
break;
}
}
//dbg(l,r);
if (l == -1) {
cout << 0 << '\n';
return ;
}
multiset<int>s0,s1;
s1.insert(a[l]);
int cnt = 1,ans = 0;
while (1) {
int ok = 0;
for (int i = r + 1;i <= n;i++) {
if (res[i - 1] == '0') {
s0.insert(a[i]);
}
else {
cnt++;
bit.add(a[i],1);
s1.insert(a[i]);
if (cnt >= k) {
int mi0;
if (s0.empty()) mi0 = 0;
else mi0 = *(s0.rbegin());
int num = bit.get(mi0);
if (cnt - num >= k) {
ok = 1;
auto it = s1.lower_bound(mi0 + 1);
int val = *(it);
ans = max(ans,val);
r = i;
break;
}
}
}
}
if (!ok) break;
bit.add(a[l],-1);
cnt--;
s1.erase(s1.find(a[l]));
for (int i = l + 1;i <= n;i++) {
if (res[i - 1] == '0') s0.erase(s0.find(a[i - 1]));
else {
l = i;
ok = 0;
break;
}
}
if (ok) break;
}
cout << ans;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int T = 1;
//cin >> T;
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5612kb
input:
5 2 1 2 3 4 5 01101
output:
2
result:
ok answer is '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
5 2 3 4 5 2 1 10101
output:
0
result:
ok answer is '0'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3572kb
input:
1 1 1 1
output:
0
result:
wrong answer expected '1', found '0'