QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#592119 | #8783. Cherry Picking | ucup-team2526 | WA | 0ms | 3604kb | C++20 | 1.8kb | 2024-09-26 20:50:21 | 2024-09-26 20:50:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define dbg(x...) \
do { \
std::cout << #x << " -> "; \
err(x); \
} while (0)
void err() {
std::cout << std::endl;
}
template<class T, class... Ts>
void err(T arg, Ts &... args) {
std::cout << fixed << setprecision(10) << arg << ' ';
err(args...);
}
void GENSHEN_START() {
int n,k;cin >> n >> k;
vector<int>a(n + 5);
for (int i = 0;i < n;i++) cin >> a[i];
string res;cin >> res;
int st = -1,ed = -1;
int cnt = 0,mx = 0;
for (int i = 0;i < n;i++) if (res[i] == '1') cnt++,mx = max(mx,a[i]);
for (int i = 0;i < n;i++) {
if (cnt == 1 && st == -1) st = i;
if (cnt == k) {
ed = i;
break;
}
}
//dbg(mx);
if (ed == -1) {
cout << 0 << '\n';
return ;
}
if (k == 1) {
cout << mx << '\n';
return ;
}
//dbg(st,ed);
multiset<int>num0,num1;
for (int i = st;i <= ed;i++) {
if (res[i] == '0') num0.insert(a[i]);
else num1.insert(a[i]);
}
int ans = 0;
while (1) {
int mi1 = *(num1.begin()),mx0 = 0;
if (!num0.empty()) mx0 = *(num0.rbegin());
if (mi1 > mx0) ans = max(ans,mi1);
//dbg(ans,mi1,mx0);
int ok1 = 0,ok2 = 0;
for (int i = st;i <= n;i++) {
if (i == st) num1.erase(num1.find(a[i]));
else if (res[i] == '0') num0.erase(num0.find(a[i]));
else {
ok1 = 1;
st = i;
num1.insert(a[i]);
break;
}
}
for (int i = ed;i <= n;i++) {
if (i == ed) num1.erase(num1.find(a[i]));
else if (res[i] == '0') num0.insert(a[i]);
else {
ok2 = 1;
ed = i;
num1.insert(a[i]);
break;
}
}
if (ok1 == 0 || ok2 == 0) break;
}
cout << ans << '\n';
return ;
}
signed main()
{
ios::sync_with_stdio(false);cin.tie(nullptr);
int T = 1;
//cin >> T;
while (T--) GENSHEN_START();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3604kb
input:
5 2 1 2 3 4 5 01101
output:
0
result:
wrong answer expected '2', found '0'