QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#592122 | #8783. Cherry Picking | ucup-team2526 | WA | 0ms | 3868kb | C++20 | 1.8kb | 2024-09-26 20:50:56 | 2024-09-26 20:50:56 |
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') mx = max(mx,a[i]);
for (int i = 0;i < n;i++) {
if (res[i] == '1') cnt++;
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3576kb
input:
5 2 1 2 3 4 5 01101
output:
2
result:
ok answer is '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
5 2 3 4 5 2 1 10101
output:
0
result:
ok answer is '0'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
1 1 1 1
output:
1
result:
ok answer is '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3868kb
input:
1 1 1 0
output:
0
result:
ok answer is '0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
5 3 8 3 5 2 7 10101
output:
5
result:
ok answer is '5'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
10 3 1 10 2 3 9 3 1 6 9 3 1100110001
output:
0
result:
ok answer is '0'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
10 1 6 7 2 10 8 4 4 9 7 9 0111011000
output:
10
result:
ok answer is '10'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
10 2 4 5 9 6 9 10 6 9 2 7 1100010100
output:
9
result:
ok answer is '9'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
10 3 2 10 8 5 8 3 7 9 9 1 1100011100
output:
3
result:
ok answer is '3'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
10 5 5 5 9 2 7 2 4 8 4 8 1010001100
output:
0
result:
ok answer is '0'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
10 10 6 5 8 3 2 8 6 4 5 5 0111001100
output:
0
result:
ok answer is '0'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
100 1 13 90 87 79 34 66 76 58 65 37 63 38 84 88 89 98 63 55 16 39 64 50 28 64 4 69 40 51 75 37 11 9 20 29 36 29 30 61 38 54 92 78 72 36 78 24 78 8 98 11 2 41 64 51 45 67 27 80 67 84 73 50 99 82 39 70 84 18 54 43 85 96 59 98 82 5 57 46 68 31 97 89 21 65 57 37 58 25 30 40 15 76 44 85 75 65 22 97 93 82...
output:
97
result:
ok answer is '97'
Test #13:
score: -100
Wrong Answer
time: 0ms
memory: 3524kb
input:
100 2 91 44 64 58 26 25 62 97 13 27 8 49 93 15 43 16 8 96 98 48 43 7 41 81 61 90 10 69 49 24 48 22 32 59 10 67 45 54 53 47 47 71 48 48 18 42 45 17 42 96 23 37 2 38 66 22 31 83 89 23 51 81 56 71 58 61 22 67 41 58 93 67 90 58 65 50 64 1 12 58 25 20 81 25 99 87 72 63 42 51 80 93 42 1 22 99 38 66 59 87 ...
output:
90
result:
wrong answer expected '93', found '90'