QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#517847 | #8783. Cherry Picking | SocialPanda | WA | 1ms | 6920kb | C++23 | 1.3kb | 2024-08-13 14:09:23 | 2024-08-13 14:09:24 |
Judging History
answer
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
//#define int long long
//#define LL long long
#define double long double
//#define lf Lf
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define PII pair<int,int>
#define Gheap priority_queue<int,vector<int>,greater<int>>
#define Lheap priority_queue<int>
#define MAXN 0x3f3f3f3f
#define MINN -0x3f3f3f3f
using namespace std;
const int N=1e6+100,M=2*N;
//int e[N],w[M],h[M],ne[M],idx;
int a[N];
vector<int> v(N);
string s;
int n,k;
void solve()
{
int ans=-1;
cin>>n>>k;
for(int i=1;i<=n;i++) {cin>>a[i];v[i]=a[i];}
cin>>s;s=' '+s;
sort(v.begin()+1,v.begin()+1+n);
int maxx=0,cnt=0;
Gheap q;
for(int i=1;i<=n;i++)
{
if(s[i]=='0')
{
maxx=max(maxx,a[i]);
if(q.size() and a[i]>q.top()) cnt=0;
}
else
{
if(a[i]>maxx) cnt++;
else cnt=0;
q.push(a[i]);
if(cnt>=k)
{
ans=max(ans,maxx);
}
}
}
if(ans==-1) cout<<0<<endl;
else
{
cout<<*upper_bound(v.begin()+1,v.begin()+1+n,ans)<<endl;
}
}
/*
8 3 5 2 7
1 0 1 0 1
*/
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt=1;
//cin >> tt;
while(tt--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 6744kb
input:
5 2 1 2 3 4 5 01101
output:
2
result:
ok answer is '2'
Test #2:
score: 0
Accepted
time: 1ms
memory: 6880kb
input:
5 2 3 4 5 2 1 10101
output:
0
result:
ok answer is '0'
Test #3:
score: 0
Accepted
time: 0ms
memory: 6852kb
input:
1 1 1 1
output:
1
result:
ok answer is '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 6880kb
input:
1 1 1 0
output:
0
result:
ok answer is '0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 6880kb
input:
5 3 8 3 5 2 7 10101
output:
5
result:
ok answer is '5'
Test #6:
score: 0
Accepted
time: 1ms
memory: 6920kb
input:
10 3 1 10 2 3 9 3 1 6 9 3 1100110001
output:
0
result:
ok answer is '0'
Test #7:
score: -100
Wrong Answer
time: 1ms
memory: 6880kb
input:
10 1 6 7 2 10 8 4 4 9 7 9 0111011000
output:
7
result:
wrong answer expected '10', found '7'