QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#517842#8783. Cherry PickingSocialPandaWA 2ms6944kbC++231.3kb2024-08-13 14:07:182024-08-13 14:07:18

Judging History

你现在查看的是最新测评结果

  • [2024-08-13 14:07:18]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:6944kb
  • [2024-08-13 14:07:18]
  • 提交

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=0;
	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==0) cout<<ans<<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: 1ms
memory: 6740kb

input:

5 2
1 2 3 4 5
01101

output:

2

result:

ok answer is '2'

Test #2:

score: 0
Accepted
time: 0ms
memory: 6688kb

input:

5 2
3 4 5 2 1
10101

output:

0

result:

ok answer is '0'

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 6944kb

input:

1 1
1
1

output:

0

result:

wrong answer expected '1', found '0'