QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#592113 | #8783. Cherry Picking | ucup-team2526 | WA | 0ms | 3768kb | C++20 | 1.8kb | 2024-09-26 20:48:44 | 2024-09-26 20:48:44 |
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]);
if (cnt == 1 && st == -1) st = i;
if (cnt == k) {
ed = i;
break;
}
}
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: 100
Accepted
time: 0ms
memory: 3544kb
input:
5 2 1 2 3 4 5 01101
output:
2
result:
ok answer is '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3484kb
input:
5 2 3 4 5 2 1 10101
output:
0
result:
ok answer is '0'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3768kb
input:
1 1 1 1
output:
1
result:
ok answer is '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3532kb
input:
1 1 1 0
output:
0
result:
ok answer is '0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
5 3 8 3 5 2 7 10101
output:
5
result:
ok answer is '5'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3768kb
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: 0ms
memory: 3548kb
input:
10 1 6 7 2 10 8 4 4 9 7 9 0111011000
output:
7
result:
wrong answer expected '10', found '7'